$sleep = min(1000000, round(log10($arg) * 1000000, 0));
usleep($sleep);
+ $pid = pcntl_waitpid(-1, $status, WNOHANG);
+ Logger::info('Checked children status via pcntl_waitpid', ['pid' => $pid, 'status' => $status]);
+
$timeout = ($seconds >= $wait_interval);
} while (!$timeout && !Worker::IPCJobsExists());
DI::process()->end();
Logger::info('Worker ended', ['cron' => $do_cron, 'pid' => getmypid()]);
+
+ DBA::disconnect();
+/*
+ $php = '/usr/bin/php';
+ $param = ['bin/worker.php'];
+ if ($do_cron) {
+ $param[] = 'no_cron';
+ }
+ pcntl_exec($php, $param);
+ Logger::warning('Error calling worker', ['cron' => $do_cron, 'pid' => getmypid()]);
+*/
exit();
}
*/
public static function spawnWorker($do_cron = false)
{
- Logger::notice("Spawn", ['do_cron' => $do_cron, 'callstack' => System::callstack(20)]);
- // Worker and daemon are started from the command line.
- // This means that this is executed by a PHP interpreter without runtime limitations
- if (function_exists('pcntl_fork') && in_array(DI::mode()->getExecutor(), [Mode::DAEMON, Mode::WORKER])) {
+ if (self::isDaemonMode()) {
self::forkProcess($do_cron);
+ self::IPCSetJobState(false);
} else {
$process = new Core\Process(DI::logger(), DI::mode(), DI::config(),
DI::modelProcess(), DI::app()->getBasePath(), getmypid());
$process->run('bin/worker.php', ['no_cron' => !$do_cron]);
}
-
- // after spawning we have to remove the flag.
- if (self::isDaemonMode()) {
- self::IPCSetJobState(false);
- }
}
/**
return $daemon_mode;
}
+ if (!function_exists('pcntl_fork')) {
+ self::$daemon_mode = false;
+ return false;
+ }
+
$pidfile = DI::config()->get('system', 'pidfile');
if (empty($pidfile)) {
// No pid file, no daemon