]>
git.wh0rd.org - tt-rss.git/blob - update_daemon.php
3 // this daemon runs in the background and updates all feeds
8 define('MAGPIE_CACHE_DIR', '/var/tmp/magpie-ttrss-cache-daemon');
9 define('DISABLE_SESSIONS', true);
11 require_once "sanity_check.php";
12 require_once "config.php";
14 if (!ENABLE_UPDATE_DAEMON
) {
15 die("Please enable option ENABLE_UPDATE_DAEMON in config.php");
18 require_once "db.php";
19 require_once "db-prefs.php";
20 require_once "functions.php";
21 require_once "magpierss/rss_fetch.inc";
23 function sigint_handler() {
24 unlink("update_daemon.lock");
25 die("Received SIGINT. Exiting.\n");
28 pcntl_signal(SIGINT
, sigint_handler
);
30 $lock_handle = make_lockfile("update_daemon.lock");
33 die("error: Can't create lockfile ($lock_filename). ".
34 "Maybe another daemon is already running.");
37 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
40 if (DB_TYPE
== "mysql") {
43 // PG seems to display its own errors just fine by default.
47 if (DB_TYPE
== "pgsql") {
48 pg_query("set client_encoding = 'utf-8'");
53 // FIXME: get all scheduled updates w/forced refetch
54 // Stub, until I figure out if it is really needed.
56 # $result = db_query($link, "SELECT * FROM ttrss_scheduled_updates ORDER BY id");
57 # while ($line = db_fetch_assoc($result)) {
58 # print "Scheduled feed update: " . $line["feed_id"] . ", UID: " .
59 # $line["owner_uid"] . "\n";
62 // Process all other feeds using last_updated and interval parameters
64 $result = db_query($link, "SELECT feed_url,id,owner_uid,
65 SUBSTRING(last_updated,1,19) AS last_updated,
66 update_interval FROM ttrss_feeds ORDER BY last_updated DESC");
68 while ($line = db_fetch_assoc($result)) {
70 $upd_intl = $line["update_interval"];
71 $user_id = $line["owner_uid"];
73 if (!$upd_intl ||
$upd_intl == 0) {
74 $upd_intl = get_pref($link, 'DEFAULT_UPDATE_INTERVAL', $user_id);
78 # print "Updates disabled.\n";
82 print "Feed: " . $line["feed_url"] . ": ";
84 printf("(%d/%d, %d) ", time() - strtotime($line["last_updated"]),
85 $upd_intl*60, $owner_uid);
87 if (!$line["last_updated"] ||
88 time() - strtotime($line["last_updated"]) > ($upd_intl * 60)) {
90 print "Updating...\n";
91 update_rss_feed($link, $line["feed_url"], $line["id"], true);
92 sleep(3); // prevent flood (FIXME make this an option?)
94 print "Update not needed.\n";
98 print "Sleeping for " . DAEMON_SLEEP_INTERVAL
. " seconds...\n";
100 sleep(DAEMON_SLEEP_INTERVAL
);