]> git.wh0rd.org - tt-rss.git/commitdiff
update_daemon2: check for dead children before spawning
authorAndrew Dolgov <fox@madoka.spb.ru>
Thu, 24 Jan 2008 08:46:09 +0000 (09:46 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Thu, 24 Jan 2008 08:46:09 +0000 (09:46 +0100)
update_daemon2.php

index 7e06cf9a9b64bc775fc182a34a3b3cab84bb781a..326b69e49dce1905d22f9c98c7567bb994fd4e9a 100644 (file)
 
        $last_checkpoint = -1;
 
-       function sigalrm_handler() {
-               die("received SIGALRM, hang in feed update?\n");
-       }
-
-       function sigchld_handler($signal) {
+       function reap_children() {
                global $children;
 
                $tmp = array();
 
                $children = $tmp;
 
-               $running_jobs = count($children);
+               return count($tmp);
+       }
+
+       function sigalrm_handler() {
+               die("received SIGALRM, hang in feed update?\n");
+       }
+
+       function sigchld_handler($signal) {
+               $running_jobs = reap_children();
 
                _debug("[SIGCHLD] jobs left: $running_jobs");
+
                pcntl_waitpid(-1, $status, WNOHANG);
        }
 
 
                if ($last_checkpoint + SPAWN_INTERVAL < time()) {
 
+                       reap_children();
+
                        for ($j = count($children); $j < MAX_JOBS; $j++) {
                                $pid = pcntl_fork();
                                if ($pid == -1) {