3 define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE
);
4 define('DISABLE_SESSIONS', true);
6 if (!defined('PHP_EXECUTABLE'))
7 define('PHP_EXECUTABLE', '/usr/bin/php');
9 error_reporting(DEFAULT_ERROR_LEVEL
);
11 require_once "sanity_check.php";
12 require_once "config.php";
13 require_once "db.php";
14 require_once "db-prefs.php";
15 require_once "functions.php";
19 if (!$op ||
$op == "-help") {
20 print "Tiny Tiny RSS data update script.\n\n";
22 print " -feeds - update feeds\n";
23 print " -feedbrowser - update feedbrowser\n";
24 print " -daemon - start single-process update daemon\n";
25 print " -help - show this help\n";
29 if ($op != "-daemon") {
30 $lock_filename = "update.lock";
32 $lock_filename = "update_daemon.lock";
35 $lock_handle = make_lockfile($lock_filename);
38 // Try to lock a file in order to avoid concurrent update.
40 die("error: Can't create lockfile ($lock_filename). ".
41 "Maybe another update process is already running.\n");
44 // Create a database connection.
45 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
48 if (DB_TYPE
== "mysql") {
51 // PG seems to display its own errors just fine by default.
55 init_connection($link);
57 if ($op == "-feeds") {
58 // Update all feeds needing a update.
59 update_daemon_common($link);
62 if ($op == "-feedbrowser") {
63 $count = update_feedbrowser_cache($link);
64 print "Finished, $count feeds processed.\n";
67 if ($op == "-daemon") {
68 if (!ENABLE_UPDATE_DAEMON
)
69 die("Please enable option ENABLE_UPDATE_DAEMON in config.php\n");
72 passthru(PHP_EXECUTABLE
. " " . $argv[0] . " -daemon-loop");
73 _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL
. " seconds...");
74 sleep(DAEMON_SLEEP_INTERVAL
);
78 if ($op == "-daemon-loop") {
79 if (!make_stampfile('update_daemon.stamp')) {
80 die("error: unable to create stampfile\n");
83 // Call to the feed batch update function
84 // or regenerate feedbrowser cache
86 if (rand(0,100) > 30) {
87 update_daemon_common($link);
89 $count = update_feedbrowser_cache($link);
90 _debug("Finished, $count feeds processed.");
97 unlink(LOCK_DIRECTORY
. "/$lock_filename");