2007-03-02 15:41:57 +01:00
|
|
|
#!/usr/bin/php
|
2006-08-19 09:04:45 +02:00
|
|
|
<?php
|
2006-02-11 14:52:17 +01:00
|
|
|
// this daemon runs in the background and updates all feeds
|
|
|
|
// continuously
|
|
|
|
|
2007-03-15 05:57:24 +01:00
|
|
|
// define('DEFAULT_ERROR_LEVEL', E_ALL);
|
|
|
|
define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE);
|
2006-04-20 07:16:41 +02:00
|
|
|
|
2006-02-12 08:21:43 +01:00
|
|
|
declare(ticks = 1);
|
2006-02-11 14:52:17 +01:00
|
|
|
|
|
|
|
define('MAGPIE_CACHE_DIR', '/var/tmp/magpie-ttrss-cache-daemon');
|
2007-08-25 18:24:18 +02:00
|
|
|
define('SIMPLEPIE_CACHE_DIR', '/var/tmp/simplepie-ttrss-cache-daemon');
|
2006-02-11 14:52:17 +01:00
|
|
|
define('DISABLE_SESSIONS', true);
|
2008-01-23 19:31:11 +01:00
|
|
|
define('PHP_EXECUTABLE', '/usr/bin/php');
|
2007-03-15 05:57:24 +01:00
|
|
|
|
|
|
|
require_once "version.php";
|
|
|
|
|
2008-01-24 07:03:18 +01:00
|
|
|
if (strpos(VERSION, ".99") !== false || getenv('DAEMON_XDEBUG')) {
|
2007-03-15 05:57:24 +01:00
|
|
|
define('DAEMON_EXTENDED_DEBUG', true);
|
|
|
|
}
|
2006-02-11 14:52:17 +01:00
|
|
|
|
2006-02-27 09:40:53 +01:00
|
|
|
define('PURGE_INTERVAL', 3600); // seconds
|
|
|
|
|
2006-02-11 14:52:17 +01:00
|
|
|
require_once "sanity_check.php";
|
|
|
|
require_once "config.php";
|
2006-02-12 08:50:35 +01:00
|
|
|
|
|
|
|
if (!ENABLE_UPDATE_DAEMON) {
|
2006-08-20 12:19:10 +02:00
|
|
|
die("Please enable option ENABLE_UPDATE_DAEMON in config.php\n");
|
2006-02-12 08:50:35 +01:00
|
|
|
}
|
|
|
|
|
2006-02-11 14:52:17 +01:00
|
|
|
require_once "db.php";
|
|
|
|
require_once "db-prefs.php";
|
|
|
|
require_once "functions.php";
|
|
|
|
require_once "magpierss/rss_fetch.inc";
|
|
|
|
|
2007-03-15 05:57:24 +01:00
|
|
|
error_reporting(DEFAULT_ERROR_LEVEL);
|
2007-03-14 15:50:28 +01:00
|
|
|
|
2006-02-12 08:21:43 +01:00
|
|
|
function sigint_handler() {
|
2008-01-17 06:33:52 +01:00
|
|
|
unlink(LOCK_DIRECTORY . "/update_daemon.lock");
|
2006-02-12 08:21:43 +01:00
|
|
|
die("Received SIGINT. Exiting.\n");
|
|
|
|
}
|
|
|
|
|
2007-03-15 16:45:42 +01:00
|
|
|
function sigalrm_handler() {
|
|
|
|
die("received SIGALRM, hang in feed update?\n");
|
|
|
|
}
|
|
|
|
|
2006-02-12 08:21:43 +01:00
|
|
|
pcntl_signal(SIGINT, sigint_handler);
|
2007-03-15 16:45:42 +01:00
|
|
|
pcntl_signal(SIGALRM, sigalrm_handler);
|
2006-02-12 08:21:43 +01:00
|
|
|
|
|
|
|
$lock_handle = make_lockfile("update_daemon.lock");
|
|
|
|
|
|
|
|
if (!$lock_handle) {
|
|
|
|
die("error: Can't create lockfile ($lock_filename). ".
|
2006-08-20 12:19:10 +02:00
|
|
|
"Maybe another daemon is already running.\n");
|
2006-02-12 08:21:43 +01:00
|
|
|
}
|
|
|
|
|
2006-02-11 14:52:17 +01:00
|
|
|
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
|
|
|
|
|
|
|
if (!$link) {
|
|
|
|
if (DB_TYPE == "mysql") {
|
|
|
|
print mysql_error();
|
|
|
|
}
|
|
|
|
// PG seems to display its own errors just fine by default.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DB_TYPE == "pgsql") {
|
|
|
|
pg_query("set client_encoding = 'utf-8'");
|
2007-02-20 09:33:17 +01:00
|
|
|
pg_set_client_encoding("UNICODE");
|
2007-08-17 18:02:15 +02:00
|
|
|
} else {
|
2007-08-21 12:47:25 +02:00
|
|
|
if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
|
|
|
|
db_query($link, "SET NAMES " . MYSQL_CHARSET);
|
2007-08-25 06:28:10 +02:00
|
|
|
// db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
|
2007-08-21 12:47:25 +02:00
|
|
|
}
|
2006-02-11 14:52:17 +01:00
|
|
|
}
|
|
|
|
|
2008-01-23 19:31:11 +01:00
|
|
|
db_close($link);
|
|
|
|
|
2006-02-27 09:40:53 +01:00
|
|
|
$last_purge = 0;
|
|
|
|
|
2006-02-11 15:13:23 +01:00
|
|
|
while (true) {
|
2006-02-26 08:09:48 +01:00
|
|
|
|
2008-01-23 19:31:11 +01:00
|
|
|
passthru(PHP_EXECUTABLE . " update_daemon_loop.php SRV_RUN_OK");
|
2006-08-21 08:43:38 +02:00
|
|
|
|
2007-03-08 18:36:42 +01:00
|
|
|
_debug("Sleeping for " . DAEMON_SLEEP_INTERVAL . " seconds...");
|
2006-02-11 15:13:23 +01:00
|
|
|
|
2006-02-12 09:04:27 +01:00
|
|
|
sleep(DAEMON_SLEEP_INTERVAL);
|
2006-02-11 14:52:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|