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