]> git.wh0rd.org - tt-rss.git/blobdiff - update_daemon.php
bump up debugging in daemon
[tt-rss.git] / update_daemon.php
index a6fb5461d58d09eacef8b48d9825244212763914..f99e4f76379f13ded6169310c5ac414f1ad38fed 100644 (file)
@@ -1,5 +1,5 @@
-#!/usr/bin/php4
-<?
+#!/usr/bin/php
+<?php
        // this daemon runs in the background and updates all feeds
        // continuously
 
@@ -9,6 +9,7 @@
 
        define('MAGPIE_CACHE_DIR', '/var/tmp/magpie-ttrss-cache-daemon');
        define('DISABLE_SESSIONS', true);
+       define('DAEMON_EXTENDED_DEBUG', true);
 
        define('PURGE_INTERVAL', 3600); // seconds
 
@@ -16,7 +17,7 @@
        require_once "config.php";
 
        if (!ENABLE_UPDATE_DAEMON) {
-               die("Please enable option ENABLE_UPDATE_DAEMON in config.php");
+               die("Please enable option ENABLE_UPDATE_DAEMON in config.php\n");
        }
        
        require_once "db.php";
@@ -24,6 +25,8 @@
        require_once "functions.php";
        require_once "magpierss/rss_fetch.inc";
 
+       error_reporting(E_ALL);
+
        function sigint_handler() {
                unlink("update_daemon.lock");
                die("Received SIGINT. Exiting.\n");
@@ -35,7 +38,7 @@
 
        if (!$lock_handle) {
                die("error: Can't create lockfile ($lock_filename). ".
-                       "Maybe another daemon is already running.");
+                       "Maybe another daemon is already running.\n");
        }
 
        $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); 
@@ -50,6 +53,7 @@
 
        if (DB_TYPE == "pgsql") {
                pg_query("set client_encoding = 'utf-8'");
+               pg_set_client_encoding("UNICODE");
        }
 
        $last_purge = 0;
@@ -57,7 +61,7 @@
        while (true) {
 
                if (time() - $last_purge > PURGE_INTERVAL) {
-                       print "Purging old posts (random 30 feeds)...\n";
+                       _debug("Purging old posts (random 30 feeds)...");
                        global_purge_old_posts($link, true, 30);
                        $last_purge = time();
                }
 
                $user_prefs_cache = array();
 
-               printf("Scheduled %d feeds to update...\n", db_num_rows($result));
+               _debug(sprintf("Scheduled %d feeds to update...\n", db_num_rows($result)));
                
                while ($line = db_fetch_assoc($result)) {
        
                                continue; 
                        }
        
-                       print "Feed: " . $line["feed_url"] . ": ";
+                       _debug("Feed: " . $line["feed_url"]);
 
-                       printf("(%d/%d, %d) ", time() - strtotime($line["last_updated"]),
-                               $upd_intl*60, $user_id);
+//                     _debug(sprintf("\tLU: %d, INTL: %d, UID: %d) ", 
+//                             time() - strtotime($line["last_updated"]), $upd_intl*60, $user_id));
        
                        if (!$line["last_updated"] || 
                                time() - strtotime($line["last_updated"]) > ($upd_intl * 60)) {
-       
-                               print "Updating...\n";  
+
+                               _debug("Updating...");
+
                                update_rss_feed($link, $line["feed_url"], $line["id"], true);   
                                sleep(1); // prevent flood (FIXME make this an option?)
                        } else {
-                               print "Update not needed.\n";
+                               _debug("Update not needed.");
                        }
                }
 
-               print "Sleeping for " . DAEMON_SLEEP_INTERVAL . " seconds...\n";
+               if (DAEMON_SENDS_DIGESTS) send_headlines_digests($link);
+
+               _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL . " seconds...");
                
                sleep(DAEMON_SLEEP_INTERVAL);
        }