]>
Commit | Line | Data |
---|---|---|
fd631206 AD |
1 | #!/usr/bin/php |
2 | <?php | |
3 | // this daemon runs in the background and updates all feeds | |
4 | // continuously | |
5 | ||
6 | if ($argv[1] != "SRV_RUN_OK") { | |
7 | die("This script should be run by update_daemon.php\n"); | |
8 | } | |
9 | ||
10 | // define('DEFAULT_ERROR_LEVEL', E_ALL); | |
11 | define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE); | |
12 | ||
13 | declare(ticks = 1); | |
14 | ||
15 | define('MAGPIE_CACHE_DIR', '/var/tmp/magpie-ttrss-cache-daemon'); | |
16 | define('SIMPLEPIE_CACHE_DIR', '/var/tmp/simplepie-ttrss-cache-daemon'); | |
17 | define('DISABLE_SESSIONS', true); | |
18 | ||
19 | require_once "version.php"; | |
20 | ||
21 | if (strpos(VERSION, ".99") !== false) { | |
22 | define('DAEMON_EXTENDED_DEBUG', true); | |
23 | } | |
24 | ||
25 | define('PURGE_INTERVAL', 3600); // seconds | |
26 | ||
27 | require_once "sanity_check.php"; | |
28 | require_once "config.php"; | |
29 | ||
30 | if (!ENABLE_UPDATE_DAEMON) { | |
31 | die("Please enable option ENABLE_UPDATE_DAEMON in config.php\n"); | |
32 | } | |
33 | ||
34 | require_once "db.php"; | |
35 | require_once "db-prefs.php"; | |
36 | require_once "functions.php"; | |
816cdfb7 | 37 | require_once "lib/magpierss/rss_fetch.inc"; |
fd631206 AD |
38 | |
39 | error_reporting(DEFAULT_ERROR_LEVEL); | |
40 | ||
41 | function sigalrm_handler() { | |
42 | die("received SIGALRM, hang in feed update?\n"); | |
43 | } | |
44 | ||
45 | pcntl_signal(SIGALRM, sigalrm_handler); | |
46 | ||
47 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); | |
48 | ||
49 | if (!$link) { | |
50 | if (DB_TYPE == "mysql") { | |
51 | print mysql_error(); | |
52 | } | |
53 | // PG seems to display its own errors just fine by default. | |
54 | return; | |
55 | } | |
56 | ||
f29ba148 | 57 | init_connection($link); |
fd631206 AD |
58 | |
59 | $last_purge = 0; | |
60 | ||
61 | if (!make_stampfile('update_daemon.stamp')) { | |
62 | print "error: unable to create stampfile"; | |
63 | die; | |
64 | } | |
65 | ||
3907ef71 | 66 | /* if (time() - $last_purge > PURGE_INTERVAL) { |
fd631206 AD |
67 | _debug("Purging old posts (random 30 feeds)..."); |
68 | global_purge_old_posts($link, true, 30); | |
69 | $last_purge = time(); | |
3907ef71 | 70 | } */ |
fd631206 | 71 | |
e3b54693 AD |
72 | // Call to the feed batch update function |
73 | // or regenerate feedbrowser cache | |
fd631206 | 74 | |
e3b54693 AD |
75 | if (rand(0,100) > 50) { |
76 | update_daemon_common($link); | |
fd631206 | 77 | } else { |
e3b54693 | 78 | $count = update_feedbrowser_cache($link); |
b6d486a3 | 79 | _debug("Finished, $count feeds processed."); |
e3b54693 | 80 | } |
fd631206 | 81 | |
fd631206 AD |
82 | db_close($link); |
83 | ||
84 | ?> |