]> git.wh0rd.org - tt-rss.git/blobdiff - update_daemon2.php
daemon: fallback automatically when pcntl_signal() is not present
[tt-rss.git] / update_daemon2.php
old mode 100644 (file)
new mode 100755 (executable)
index 1b4007a..779373a
@@ -12,8 +12,6 @@
        define('SIMPLEPIE_CACHE_DIR',   '/var/tmp/simplepie-ttrss-cache-daemon');
        define('DISABLE_SESSIONS', true);
 
-       define('MAX_JOBS', 2);
-
        require_once "version.php";
 
        if (strpos(VERSION, ".99") !== false || getenv('DAEMON_XDEBUG')) {
        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);
 
 
        db_close($link);
 
-
        while (true) {
 
                // Since sleep is interupted by SIGCHLD, we need another way to
                                                return;
                                        }
 
-                                       if (DB_TYPE == "pgsql") {
-                                               pg_query("set client_encoding = 'utf-8'");
-                                               pg_set_client_encoding("UNICODE");
-                                       } else {
-                                               if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
-                                                       db_query($link, "SET NAMES " . MYSQL_CHARSET);
-                                                       // db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
-                                               }
-                                       }
+                                       init_connection($link);
 
                                        // We disable stamp file, since it is of no use in a multiprocess update.
                                        // not really, tho for the time being -fox
                                                print "warning: unable to create stampfile";
                                        }       
 
-                                       // $last_purge = 0;
-
-                                       // if (time() - $last_purge > PURGE_INTERVAL) {
-
                                        // FIXME : $last_purge is of no use in a multiprocess update.
                                        // FIXME : We ALWAYS purge old posts.
-                                       _debug("Purging old posts (random 30 feeds)...");
-                                       global_purge_old_posts($link, true, 30);
+                                       //_debug("Purging old posts (random 30 feeds)...");
+                                       //global_purge_old_posts($link, true, 30);
 
-                                       //      $last_purge = time();
-                                       // }
+                                       // Call to the feed batch update function 
+                                       // or regenerate feedbrowser cache
 
-                                       // Call to the feed batch update function
-                                       update_daemon_common($link);
+                                       if (rand(0,100) > 50) {
+                                               update_daemon_common($link);
+                                       } else {
+                                               $count = update_feedbrowser_cache($link);
+                                               _debug("Finished, $count feeds processed.");
+                                       }
 
                                        _debug("Elapsed time: " . (time() - $start_timestamp) . " second(s)");