fork - PHP process forking with Pheanstalk -
i'm trying create php script runs in background , forks child processes. (i'm aware explode server; there safeguards in place outside scope of question)
in nutshell, code works this:
$pids = array(); $ok = true; while ($ok) { $job = $pheanstalk->watch('jobs')->ignore('default')->reserve(); echo 'reserved job #' . $job->getid(); $pids[$job->getid()] = pcntl_fork(); if(!$pids[$job->getid()]) { dostuff(); $pheanstalk->delete($job); exit(); } }
the problem once fork process, error:
reserved job #0 php fatal error: uncaught exception 'pheanstalk_exception_serverexception' message 'cannot delete job 0: not_found'
my question is, how pheanstalk returned job no id , no payload? feels $pheanstalk damaged once fork it. if remove forking, works fine. (though has wait on each process)
put if condition before delete pheanstalk job:
if ($job) $pheanstalk->delete($job);
thats because possible php instance of file has removed job before code reaches place. (the other instance still retrieve job using reserve() until job deleted queue.
Comments
Post a Comment