]>
git.wh0rd.org - tt-rss.git/blob - update_daemon.php
3 // this daemon runs in the background and updates all feeds
8 define('SLEEP_INTERVAL', 60); // seconds between update runs
9 define('MAGPIE_CACHE_DIR', '/var/tmp/magpie-ttrss-cache-daemon');
10 define('DISABLE_SESSIONS', true);
12 require_once "sanity_check.php";
13 require_once "config.php";
15 if (!ENABLE_UPDATE_DAEMON
) {
16 die("Please enable option ENABLE_UPDATE_DAEMON in config.php");
19 require_once "db.php";
20 require_once "db-prefs.php";
21 require_once "functions.php";
22 require_once "magpierss/rss_fetch.inc";
24 function sigint_handler() {
25 unlink("update_daemon.lock");
26 die("Received SIGINT. Exiting.\n");
29 pcntl_signal(SIGINT
, sigint_handler
);
31 $lock_handle = make_lockfile("update_daemon.lock");
34 die("error: Can't create lockfile ($lock_filename). ".
35 "Maybe another daemon is already running.");
38 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
41 if (DB_TYPE
== "mysql") {
44 // PG seems to display its own errors just fine by default.
48 if (DB_TYPE
== "pgsql") {
49 pg_query("set client_encoding = 'utf-8'");
54 // FIXME: get all scheduled updates w/forced refetch
55 // Stub, until I figure out if it is really needed.
57 # $result = db_query($link, "SELECT * FROM ttrss_scheduled_updates ORDER BY id");
58 # while ($line = db_fetch_assoc($result)) {
59 # print "Scheduled feed update: " . $line["feed_id"] . ", UID: " .
60 # $line["owner_uid"] . "\n";
63 // Process all other feeds using last_updated and interval parameters
65 $result = db_query($link, "SELECT feed_url,id,owner_uid,
66 SUBSTRING(last_updated,1,19) AS last_updated,
67 update_interval FROM ttrss_feeds ORDER BY last_updated DESC");
69 while ($line = db_fetch_assoc($result)) {
71 print "Feed: " . $line["feed_url"] . ": ";
73 $upd_intl = $line["update_interval"];
75 $user_id = $line["owner_uid"];
77 if (!$upd_intl ||
$upd_intl == 0) {
78 $upd_intl = get_pref($link, 'DEFAULT_UPDATE_INTERVAL', $user_id);
82 print "Updates disabled.\n";
86 # printf("%d ? %d\n", time() - strtotime($line["last_updated"]) > $upd_intl*60,
89 if (!$line["last_updated"] ||
90 time() - strtotime($line["last_updated"]) > ($upd_intl * 60)) {
92 print "Updating...\n";
93 update_rss_feed($link, $line["feed_url"], $line["id"], true);
95 print "Update not needed.\n";
99 print "Sleeping for " . SLEEP_INTERVAL
. " seconds...\n";
101 sleep(SLEEP_INTERVAL
);