]> git.wh0rd.org - tt-rss.git/blame - update_daemon.php
pref-labels: disable table caption
[tt-rss.git] / update_daemon.php
CommitLineData
cd2cd415 1#!/usr/bin/php
1d3a17c7 2<?php
de696427
AD
3 // this daemon runs in the background and updates all feeds
4 // continuously
5
34e420fb
AD
6 // define('DEFAULT_ERROR_LEVEL', E_ALL);
7 define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE);
550e37d5 8
6eafcac6 9 declare(ticks = 1);
de696427
AD
10
11 define('MAGPIE_CACHE_DIR', '/var/tmp/magpie-ttrss-cache-daemon');
c7d57b66 12 define('SIMPLEPIE_CACHE_DIR', '/var/tmp/simplepie-ttrss-cache-daemon');
de696427 13 define('DISABLE_SESSIONS', true);
34e420fb
AD
14
15 require_once "version.php";
16
010c16f1 17 if (strpos(VERSION, ".99") !== false || getenv('DAEMON_XDEBUG')) {
34e420fb
AD
18 define('DAEMON_EXTENDED_DEBUG', true);
19 }
de696427 20
3b3d116e
AD
21 define('PURGE_INTERVAL', 3600); // seconds
22
de696427
AD
23 require_once "sanity_check.php";
24 require_once "config.php";
c6784aea 25
64eb624c
AD
26 if (!defined('PHP_EXECUTABLE')) {
27 define('PHP_EXECUTABLE', '/usr/bin/php');
28 }
29
c6784aea 30 if (!ENABLE_UPDATE_DAEMON) {
69ff793a 31 die("Please enable option ENABLE_UPDATE_DAEMON in config.php\n");
c6784aea
AD
32 }
33
de696427
AD
34 require_once "db.php";
35 require_once "db-prefs.php";
36 require_once "functions.php";
37 require_once "magpierss/rss_fetch.inc";
38
34e420fb 39 error_reporting(DEFAULT_ERROR_LEVEL);
219bd8fc 40
6eafcac6 41 function sigint_handler() {
cfa43e02 42 unlink(LOCK_DIRECTORY . "/update_daemon.lock");
6eafcac6
AD
43 die("Received SIGINT. Exiting.\n");
44 }
45
4052b32d
AD
46 function sigalrm_handler() {
47 die("received SIGALRM, hang in feed update?\n");
48 }
49
6eafcac6 50 pcntl_signal(SIGINT, sigint_handler);
4052b32d 51 pcntl_signal(SIGALRM, sigalrm_handler);
6eafcac6
AD
52
53 $lock_handle = make_lockfile("update_daemon.lock");
54
55 if (!$lock_handle) {
56 die("error: Can't create lockfile ($lock_filename). ".
69ff793a 57 "Maybe another daemon is already running.\n");
6eafcac6
AD
58 }
59
f29ba148
AD
60 // Testing database connection.
61 // It is unnecessary to start the fork loop if database is not ok.
de696427
AD
62 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
63
64 if (!$link) {
65 if (DB_TYPE == "mysql") {
66 print mysql_error();
67 }
68 // PG seems to display its own errors just fine by default.
69 return;
70 }
71
fd631206
AD
72 db_close($link);
73
3b3d116e
AD
74 $last_purge = 0;
75
1f4ad53c 76 while (true) {
a545b564 77
fd631206 78 passthru(PHP_EXECUTABLE . " update_daemon_loop.php SRV_RUN_OK");
9cd7c995 79
6f9e33e4 80 _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL . " seconds...");
1f4ad53c 81
78ea1de0 82 sleep(DAEMON_SLEEP_INTERVAL);
de696427
AD
83 }
84
de696427
AD
85
86?>