+ $start = time();
+ Logger::info('Sleeping', ['pid' => $pid, 'until' => gmdate(DateTimeFormat::MYSQL, $start + $wait_interval)]);
+
+ do {
+ $seconds = (time() - $start);
+
+ // logarithmic wait time calculation.
+ // Background: After jobs had been started, they often fork many workers.
+ // To not waste too much time, the sleep period increases.
+ $arg = (($seconds + 1) / ($wait_interval / 9)) + 1;
+ $sleep = min(1000000, round(log10($arg) * 1000000, 0));
+ usleep($sleep);
+
+ $pid = pcntl_waitpid(-1, $status, WNOHANG);
+ if ($pid > 0) {
+ Logger::info('Children quit via pcntl_waitpid', ['pid' => $pid, 'status' => $status]);
+ }
+
+ $timeout = ($seconds >= $wait_interval);
+ } while (!$timeout && !Worker\IPC::JobsExists());
+
+ if ($timeout) {
+ $do_cron = true;
+ Logger::info('Woke up after $wait_interval seconds.', ['pid' => $pid, 'sleep' => $wait_interval]);
+ } else {
+ $do_cron = false;
+ Logger::info('Worker jobs are calling to be forked.', ['pid' => $pid]);