3 // this daemon runs in the background and updates all feeds
6 // define('DEFAULT_ERROR_LEVEL', E_ALL);
7 define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE
);
11 define('MAGPIE_CACHE_DIR', '/var/tmp/magpie-ttrss-cache-daemon');
12 define('SIMPLEPIE_CACHE_DIR', '/var/tmp/simplepie-ttrss-cache-daemon');
13 define('DISABLE_SESSIONS', true);
15 require_once "version.php";
17 if (strpos(VERSION
, ".99") !== false ||
getenv('DAEMON_XDEBUG')) {
18 define('DAEMON_EXTENDED_DEBUG', true);
21 define('PURGE_INTERVAL', 3600); // seconds
23 require_once "sanity_check.php";
24 require_once "config.php";
26 if (!defined('PHP_EXECUTABLE')) {
27 define('PHP_EXECUTABLE', '/usr/bin/php');
30 if (!ENABLE_UPDATE_DAEMON
) {
31 die("Please enable option ENABLE_UPDATE_DAEMON in config.php\n");
34 require_once "db.php";
35 require_once "db-prefs.php";
36 require_once "functions.php";
37 require_once "magpierss/rss_fetch.inc";
39 error_reporting(DEFAULT_ERROR_LEVEL
);
41 function sigint_handler() {
42 unlink(LOCK_DIRECTORY
. "/update_daemon.lock");
43 die("Received SIGINT. Exiting.\n");
46 function sigalrm_handler() {
47 die("received SIGALRM, hang in feed update?\n");
50 pcntl_signal(SIGINT
, sigint_handler
);
51 pcntl_signal(SIGALRM
, sigalrm_handler
);
53 $lock_handle = make_lockfile("update_daemon.lock");
56 die("error: Can't create lockfile ($lock_filename). ".
57 "Maybe another daemon is already running.\n");
60 // Testing database connection.
61 // It is unnecessary to start the fork loop if database is not ok.
62 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
65 if (DB_TYPE
== "mysql") {
68 // PG seems to display its own errors just fine by default.
78 passthru(PHP_EXECUTABLE
. " update_daemon_loop.php SRV_RUN_OK");
80 _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL
. " seconds...");
82 sleep(DAEMON_SLEEP_INTERVAL
);