|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2017-01-10 08:25 UTC] kalle@php.net
-Status: Open
+Status: Suspended
[2017-01-10 08:25 UTC] kalle@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 16:00:02 2025 UTC |
Description: ------------ Error when using pcntl_wait inside handle function Test script: --------------- <?php ini_set('display_errors', 1); error_reporting(E_ALL); $client = new GearmanClient; $client->addServer(); $client->addTaskBackground('handle', 'test'); $client->runTasks(); ###################################################### <?php ini_set('display_errors', 1); error_reporting(E_ALL); function doJob($i){ if($pid = pcntl_fork()){ return true; } if(-1 === $pid){ throw Exception('Unable to fork process'); } sleep($i); file_put_contents('test.log', 'Forked child' . PHP_EOL, FILE_APPEND); exit; } $worker = new GearmanWorker; $worker->addServer(); $worker->addFunction('handle', function(GearmanJob $job){ for($i = 0; $i < 10; ++$i){ doJob($i, $job->workload()); } $status = null; while(0 < ($pid = pcntl_wait($status))){ file_put_contents('test.log', 'child closed: ' . $pid . '(' . var_export($status) . ')' . PHP_EOL, FILE_APPEND); } $job->sendComplete('ok'); }); $worker->setTimeout(5000000); if(!$worker->work()){ echo 'failed'; } echo 'done'; Expected result: ---------------- Job complete normaly Actual result: -------------- Job fails and returns to queue