]> git.wh0rd.org - tt-rss.git/blame - update_daemon.php
update_daemon2: fix the never-update bug
[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);
fd631206 14 define('PHP_EXECUTABLE', '/usr/bin/php');
34e420fb
AD
15
16 require_once "version.php";
17
18 if (strpos(VERSION, ".99") !== false) {
19 define('DAEMON_EXTENDED_DEBUG', true);
20 }
de696427 21
3b3d116e
AD
22 define('PURGE_INTERVAL', 3600); // seconds
23
de696427
AD
24 require_once "sanity_check.php";
25 require_once "config.php";
c6784aea
AD
26
27 if (!ENABLE_UPDATE_DAEMON) {
69ff793a 28 die("Please enable option ENABLE_UPDATE_DAEMON in config.php\n");
c6784aea
AD
29 }
30
de696427
AD
31 require_once "db.php";
32 require_once "db-prefs.php";
33 require_once "functions.php";
34 require_once "magpierss/rss_fetch.inc";
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
6eafcac6 47 pcntl_signal(SIGINT, sigint_handler);
4052b32d 48 pcntl_signal(SIGALRM, sigalrm_handler);
6eafcac6
AD
49
50 $lock_handle = make_lockfile("update_daemon.lock");
51
52 if (!$lock_handle) {
53 die("error: Can't create lockfile ($lock_filename). ".
69ff793a 54 "Maybe another daemon is already running.\n");
6eafcac6
AD
55 }
56
de696427
AD
57 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
58
59 if (!$link) {
60 if (DB_TYPE == "mysql") {
61 print mysql_error();
62 }
63 // PG seems to display its own errors just fine by default.
64 return;
65 }
66
67 if (DB_TYPE == "pgsql") {
68 pg_query("set client_encoding = 'utf-8'");
ef063748 69 pg_set_client_encoding("UNICODE");
70dcff6b 70 } else {
bddc9788
AD
71 if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
72 db_query($link, "SET NAMES " . MYSQL_CHARSET);
75ca1986 73// db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
bddc9788 74 }
de696427
AD
75 }
76
fd631206
AD
77 db_close($link);
78
3b3d116e
AD
79 $last_purge = 0;
80
1f4ad53c 81 while (true) {
a545b564 82
fd631206 83 passthru(PHP_EXECUTABLE . " update_daemon_loop.php SRV_RUN_OK");
9cd7c995 84
6f9e33e4 85 _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL . " seconds...");
1f4ad53c 86
78ea1de0 87 sleep(DAEMON_SLEEP_INTERVAL);
de696427
AD
88 }
89
de696427
AD
90
91?>