]>
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 | ||
fd631206 AD |
15 | define('DISABLE_SESSIONS', true); |
16 | ||
17 | require_once "version.php"; | |
18 | ||
19 | if (strpos(VERSION, ".99") !== false) { | |
20 | define('DAEMON_EXTENDED_DEBUG', true); | |
21 | } | |
22 | ||
23 | define('PURGE_INTERVAL', 3600); // seconds | |
24 | ||
25 | require_once "sanity_check.php"; | |
26 | require_once "config.php"; | |
27 | ||
28 | if (!ENABLE_UPDATE_DAEMON) { | |
29 | die("Please enable option ENABLE_UPDATE_DAEMON in config.php\n"); | |
30 | } | |
31 | ||
32 | require_once "db.php"; | |
33 | require_once "db-prefs.php"; | |
34 | require_once "functions.php"; | |
816cdfb7 | 35 | require_once "lib/magpierss/rss_fetch.inc"; |
fd631206 AD |
36 | |
37 | error_reporting(DEFAULT_ERROR_LEVEL); | |
38 | ||
39 | function sigalrm_handler() { | |
40 | die("received SIGALRM, hang in feed update?\n"); | |
41 | } | |
42 | ||
43 | pcntl_signal(SIGALRM, sigalrm_handler); | |
44 | ||
45 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); | |
46 | ||
47 | if (!$link) { | |
48 | if (DB_TYPE == "mysql") { | |
49 | print mysql_error(); | |
50 | } | |
51 | // PG seems to display its own errors just fine by default. | |
52 | return; | |
53 | } | |
54 | ||
f29ba148 | 55 | init_connection($link); |
fd631206 AD |
56 | |
57 | $last_purge = 0; | |
58 | ||
59 | if (!make_stampfile('update_daemon.stamp')) { | |
60 | print "error: unable to create stampfile"; | |
61 | die; | |
62 | } | |
63 | ||
e3b54693 AD |
64 | // Call to the feed batch update function |
65 | // or regenerate feedbrowser cache | |
fd631206 | 66 | |
e3b54693 AD |
67 | if (rand(0,100) > 50) { |
68 | update_daemon_common($link); | |
fd631206 | 69 | } else { |
e3b54693 | 70 | $count = update_feedbrowser_cache($link); |
b6d486a3 | 71 | _debug("Finished, $count feeds processed."); |
e3b54693 | 72 | } |
fd631206 | 73 | |
fd631206 AD |
74 | db_close($link); |
75 | ||
76 | ?> |