X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fspawningdaemon.php;h=fd9ae43556ddc019b73987ba7f67e876ae8305f9;hb=60e0f0426133544eaaea7ff84da5f02ca86bd8cc;hp=b1961d68801c308fc25429a4cee80b028439f72d;hpb=0794ecf372ffff2e0cc93509ae3462ca0cbbc99c;p=quix0rs-gnu-social.git diff --git a/lib/spawningdaemon.php b/lib/spawningdaemon.php index b1961d6880..fd9ae43556 100644 --- a/lib/spawningdaemon.php +++ b/lib/spawningdaemon.php @@ -83,24 +83,31 @@ abstract class SpawningDaemon extends Daemon $this->log(LOG_INFO, "Spawned thread $i as pid $pid"); $children[$i] = $pid; } + sleep(common_config('queue', 'spawndelay')); } $this->log(LOG_INFO, "Waiting for children to complete."); while (count($children) > 0) { $status = null; $pid = pcntl_wait($status); - if ($pid > 0 && pcntl_wifexited($status)) { - $exitCode = pcntl_wexitstatus($status); - + if ($pid > 0) { $i = array_search($pid, $children); if ($i === false) { - $this->log(LOG_ERR, "Unrecognized child pid $pid exited with status $exitCode"); + $this->log(LOG_ERR, "Ignoring exit of unrecognized child pid $pid"); continue; } + if (pcntl_wifexited($status)) { + $exitCode = pcntl_wexitstatus($status); + $info = "status $exitCode"; + } else if (pcntl_wifsignaled($status)) { + $exitCode = self::EXIT_ERR; + $signal = pcntl_wtermsig($status); + $info = "signal $signal"; + } unset($children[$i]); if ($this->shouldRespawn($exitCode)) { - $this->log(LOG_INFO, "Thread $i pid $pid exited with status $exitCode; respawing."); + $this->log(LOG_INFO, "Thread $i pid $pid exited with $info; respawing."); $pid = pcntl_fork(); if ($pid < 0) { @@ -111,6 +118,7 @@ abstract class SpawningDaemon extends Daemon $this->log(LOG_INFO, "Respawned thread $i as pid $pid"); $children[$i] = $pid; } + sleep(common_config('queue', 'spawndelay')); } else { $this->log(LOG_INFO, "Thread $i pid $pid exited with status $exitCode; closing out thread."); }