]> git.wh0rd.org - tt-rss.git/blobdiff - update_daemon2.php
reenable piggie (refs #42)
[tt-rss.git] / update_daemon2.php
old mode 100644 (file)
new mode 100755 (executable)
index 777b835..ce6a3ee
@@ -8,8 +8,6 @@
 
        declare(ticks = 1);
 
-       define('MAGPIE_CACHE_DIR', '/var/tmp/magpie-ttrss-cache-daemon');
-       define('SIMPLEPIE_CACHE_DIR',   '/var/tmp/simplepie-ttrss-cache-daemon');
        define('DISABLE_SESSIONS', true);
 
        require_once "version.php";
        }
 
        define('PURGE_INTERVAL', 3600); // seconds
+       define('MAX_CHILD_RUNTIME', 600); // seconds
 
        require_once "sanity_check.php";
        require_once "config.php";
 
        define('MAX_JOBS', 2);
-
        define('SPAWN_INTERVAL', DAEMON_SLEEP_INTERVAL);
 
+       if (!function_exists('pcntl_fork')) {
+               die("error: This script requires PHP compiled with PCNTL module.\n");
+       }
+
        if (!ENABLE_UPDATE_DAEMON) {
-               die("Please enable option ENABLE_UPDATE_DAEMON in config.php\n");
+               die("error: Please enable option ENABLE_UPDATE_DAEMON in config.php\n");
        }
        
        require_once "db.php";
        require_once "db-prefs.php";
        require_once "functions.php";
-       require_once "magpierss/rss_fetch.inc";
+       require_once "lib/magpierss/rss_fetch.inc";
 
        error_reporting(DEFAULT_ERROR_LEVEL);
 
        $children = array();
+       $ctimes = array();
 
        $last_checkpoint = -1;
 
        function reap_children() {
                global $children;
+               global $ctimes;
 
                $tmp = array();
 
@@ -52,6 +56,7 @@
                                array_push($tmp, $pid);
                        } else {
                                _debug("[SIGCHLD] child $pid reaped.");
+                               unset($ctimes[$pid]);
                        }
                }
 
                return count($tmp);
        }
 
-       function sigalrm_handler() {
-               die("[SIGALRM] hang in feed update?\n");
+       function check_ctimes() {
+               global $ctimes;
+               
+               foreach (array_keys($ctimes) as $pid) {
+                       $started = $ctimes[$pid];
+
+                       if (time() - $started > MAX_CHILD_RUNTIME) {
+                               _debug("[MASTER] child process $pid seems to be stuck, aborting...");
+                               posix_kill($pid, SIGINT);
+                       }
+               }
        }
 
        function sigchld_handler($signal) {
@@ -77,7 +91,6 @@
                die("[SIGINT] removing lockfile and exiting.\n");
        }
 
-       pcntl_signal(SIGALRM, 'sigalrm_handler');
        pcntl_signal(SIGCHLD, 'sigchld_handler');
 
        if (file_is_locked("update_daemon.lock")) {
 
                if ($last_checkpoint + SPAWN_INTERVAL < time()) {
 
+                       check_ctimes();
                        reap_children();
 
                        for ($j = count($children); $j < MAX_JOBS; $j++) {
                                } else if ($pid) {
                                        _debug("[MASTER] spawned client $j [PID:$pid]...");
                                        array_push($children, $pid);
+                                       $ctimes[$pid] = time();
                                } else {
                                        pcntl_signal(SIGCHLD, SIG_IGN);
                                        pcntl_signal(SIGINT, SIG_DFL);