]> git.wh0rd.org - tt-rss.git/blob - update_daemon.php
move magpie to lib/
[tt-rss.git] / update_daemon.php
1 #!/usr/bin/php
2 <?php
3 // this daemon runs in the background and updates all feeds
4 // continuously
5
6 // define('DEFAULT_ERROR_LEVEL', E_ALL);
7 define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE);
8
9 declare(ticks = 1);
10
11 define('DISABLE_SESSIONS', true);
12
13 require_once "version.php";
14
15 if (strpos(VERSION, ".99") !== false || getenv('DAEMON_XDEBUG')) {
16 define('DAEMON_EXTENDED_DEBUG', true);
17 }
18
19 define('PURGE_INTERVAL', 3600); // seconds
20
21 require_once "sanity_check.php";
22 require_once "config.php";
23
24 if (!defined('PHP_EXECUTABLE')) {
25 define('PHP_EXECUTABLE', '/usr/bin/php');
26 }
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";
35
36 error_reporting(DEFAULT_ERROR_LEVEL);
37
38 function sigint_handler() {
39 unlink(LOCK_DIRECTORY . "/update_daemon.lock");
40 die("Received SIGINT. Exiting.\n");
41 }
42
43 function sigalrm_handler() {
44 die("received SIGALRM, hang in feed update?\n");
45 }
46
47 pcntl_signal(SIGINT, sigint_handler);
48 pcntl_signal(SIGALRM, sigalrm_handler);
49
50 $lock_handle = make_lockfile("update_daemon.lock");
51
52 if (!$lock_handle) {
53 die("error: Can't create lockfile ($lock_filename). ".
54 "Maybe another daemon is already running.\n");
55 }
56
57 // Testing database connection.
58 // It is unnecessary to start the fork loop if database is not ok.
59 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
60
61 if (!$link) {
62 if (DB_TYPE == "mysql") {
63 print mysql_error();
64 }
65 // PG seems to display its own errors just fine by default.
66 return;
67 }
68
69 db_close($link);
70
71 $last_purge = 0;
72
73 while (true) {
74
75 passthru(PHP_EXECUTABLE . " update_daemon_loop.php SRV_RUN_OK");
76
77 _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL . " seconds...");
78
79 sleep(DAEMON_SLEEP_INTERVAL);
80 }
81
82
83 ?>