fix compatibility with phpredis

* implement a fork helper method that closes the connection to redis before forking (instead of resetting after)
  to work around bugs with phpredis/socket fork handling
* phpredis does not automatically typecast to string, so worker name must be typecasted when registering
This commit is contained in:
Chris Boulton 2013-01-13 02:59:06 +11:00
parent f082ec872e
commit 6800fbe5ac
3 changed files with 31 additions and 39 deletions

View file

@ -184,7 +184,7 @@ class Resque_Worker
Resque_Event::trigger('beforeFork', $job);
$this->workingOn($job);
$this->child = $this->fork();
$this->child = Resque::fork();
// Forked and we're the child. Run the job.
if ($this->child === 0 || $this->child === false) {
@ -286,27 +286,6 @@ class Resque_Worker
return $queues;
}
/**
* Attempt to fork a child process from the parent to run a job in.
*
* Return values are those of pcntl_fork().
*
* @return int -1 if the fork failed, 0 for the forked child, the PID of the child for the parent.
*/
private function fork()
{
if(!function_exists('pcntl_fork')) {
return false;
}
$pid = pcntl_fork();
if($pid === -1) {
throw new RuntimeException('Unable to fork child worker.');
}
return $pid;
}
/**
* Perform necessary actions to start a worker.
*/
@ -474,7 +453,7 @@ class Resque_Worker
*/
public function registerWorker()
{
Resque::redis()->sadd('workers', $this);
Resque::redis()->sadd('workers', (string)$this);
Resque::redis()->set('worker:' . (string)$this . ':started', strftime('%a %b %d %H:%M:%S %Z %Y'));
}