]>
git.wh0rd.org - tt-rss.git/blob - update_daemon.php
3 // this daemon runs in the background and updates all feeds
6 define('SLEEP_INTERVAL', 10); // seconds
8 // TODO: allow update scheduling from users
10 define('MAGPIE_CACHE_DIR', '/var/tmp/magpie-ttrss-cache-daemon');
12 define('DISABLE_SESSIONS', true);
14 require_once "sanity_check.php";
15 require_once "config.php";
16 require_once "db.php";
17 require_once "db-prefs.php";
18 require_once "functions.php";
19 require_once "magpierss/rss_fetch.inc";
21 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
24 if (DB_TYPE
== "mysql") {
27 // PG seems to display its own errors just fine by default.
31 if (DB_TYPE
== "pgsql") {
32 pg_query("set client_encoding = 'utf-8'");
37 // FIXME: get all scheduled updates w/forced refetch
39 # $result = db_query($link, "SELECT * FROM ttrss_scheduled_updates ORDER BY id");
40 # while ($line = db_fetch_assoc($result)) {
41 # print "Scheduled feed update: " . $line["feed_id"] . ", UID: " .
42 # $line["owner_uid"] . "\n";
45 // Process all other feeds using last_updated and interval parameters
47 $result = db_query($link, "SELECT feed_url,id,owner_uid,
48 SUBSTRING(last_updated,1,19) AS last_updated,
49 update_interval FROM ttrss_feeds ORDER BY last_updated DESC");
51 while ($line = db_fetch_assoc($result)) {
53 print "Checking feed: " . $line["feed_url"] . "\n";
55 $upd_intl = $line["update_interval"];
57 $user_id = $line["owner_uid"];
59 if (!$upd_intl ||
$upd_intl == 0) {
60 $upd_intl = get_pref($link, 'DEFAULT_UPDATE_INTERVAL', $user_id);
63 # printf("%d ? %d\n", time() - strtotime($line["last_updated"]) > $upd_intl*60,
66 if (!$line["last_updated"] ||
67 time() - strtotime($line["last_updated"]) > ($upd_intl * 60)) {
69 print "Updating...\n";
71 update_rss_feed($link, $line["feed_url"], $line["id"], true);
76 print "Sleeping for " . SLEEP_INTERVAL
. " seconds...\n";
78 sleep(SLEEP_INTERVAL
);