]>
Commit | Line | Data |
---|---|---|
de696427 AD |
1 | #!/usr/bin/php4 |
2 | <? | |
3 | // this daemon runs in the background and updates all feeds | |
4 | // continuously | |
5 | ||
6 | define('SLEEP_INTERVAL', 30); // seconds | |
7 | ||
8 | // TODO: allow update scheduling from users | |
9 | ||
10 | define('MAGPIE_CACHE_DIR', '/var/tmp/magpie-ttrss-cache-daemon'); | |
11 | ||
12 | define('DISABLE_SESSIONS', true); | |
13 | ||
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"; | |
20 | ||
21 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); | |
22 | ||
23 | if (!$link) { | |
24 | if (DB_TYPE == "mysql") { | |
25 | print mysql_error(); | |
26 | } | |
27 | // PG seems to display its own errors just fine by default. | |
28 | return; | |
29 | } | |
30 | ||
31 | if (DB_TYPE == "pgsql") { | |
32 | pg_query("set client_encoding = 'utf-8'"); | |
33 | } | |
34 | ||
35 | $result = db_query($link, "SELECT feed_url,id,owner_uid, | |
36 | SUBSTRING(last_updated,1,19) AS last_updated, | |
37 | update_interval FROM ttrss_feeds ORDER BY last_updated DESC"); | |
38 | ||
39 | while ($line = db_fetch_assoc($result)) { | |
40 | ||
41 | print "Checking feed: " . $line["feed_url"] . "\n"; | |
42 | ||
43 | $upd_intl = $line["update_interval"]; | |
44 | ||
45 | $user_id = $line["owner_uid"]; | |
46 | ||
47 | if (!$upd_intl || $upd_intl == 0) { | |
48 | $upd_intl = get_pref($link, 'DEFAULT_UPDATE_INTERVAL', $user_id); | |
49 | } | |
50 | ||
9d1ef64e AD |
51 | # printf("%d ? %d\n", time() - strtotime($line["last_updated"]) > $upd_intl*60, |
52 | # $upd_intl*60); | |
53 | ||
54 | if (!$line["last_updated"] || | |
55 | time() - strtotime($line["last_updated"]) > ($upd_intl * 60)) { | |
de696427 AD |
56 | |
57 | print "Updating...\n"; | |
58 | ||
59 | update_rss_feed($link, $line["feed_url"], $line["id"], true); | |
60 | ||
61 | } | |
62 | } | |
63 | ||
9d1ef64e | 64 | // sleep(SLEEP_INTERVAL); |
de696427 AD |
65 | |
66 | db_close($link); | |
67 | ||
68 | ?> |