public final function runDaemon($job)
{
if ($this->isMultiInstance) {
$this->flushLog();
$pid = pcntl_fork();
if ($pid == -1) {
return false;
} elseif ($pid !== 0) {
static::$currentJobs[$pid] = true;
return true;
} else {
$this->cleanLog();
$this->renewConnections();
//child process must die
$this->trigger(self::EVENT_BEFORE_JOB);
$status = $this->doJob($job);
$this->trigger(self::EVENT_AFTER_JOB);
if ($status) {
$this->halt(self::EXIT_CODE_NORMAL);
} else {
$this->halt(self::EXIT_CODE_ERROR, 'Child process #' . $pid . ' return error.');
}
}
} else {
$this->trigger(self::EVENT_BEFORE_JOB);
$status = $this->doJob($job);
$this->trigger(self::EVENT_AFTER_JOB);
return $status;
}
}