]>
git.wh0rd.org - tt-rss.git/blob - update.php
3 define('DISABLE_SESSIONS', true);
5 chdir(dirname($_SERVER['SCRIPT_NAME']));
6 require_once "functions.php";
7 require_once "sanity_check.php";
8 require_once "config.php";
10 require_once "db-prefs.php";
12 if (!defined('PHP_EXECUTABLE'))
13 define('PHP_EXECUTABLE', '/usr/bin/php');
17 if (!$op ||
$op == "-help") {
18 print "Tiny Tiny RSS data update script.\n\n";
20 print " -feeds - update feeds\n";
21 print " -feedbrowser - update feedbrowser\n";
22 print " -daemon - start single-process update daemon\n";
23 print " -cleanup-tags - perform tags table maintenance\n";
24 print " -help - show this help\n";
28 if ($op != "-daemon") {
29 $lock_filename = "update.lock";
31 $lock_filename = "update_daemon.lock";
34 $lock_handle = make_lockfile($lock_filename);
37 // Try to lock a file in order to avoid concurrent update.
39 die("error: Can't create lockfile ($lock_filename). ".
40 "Maybe another update process is already running.\n");
43 // Create a database connection.
44 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
47 if (DB_TYPE
== "mysql") {
50 // PG seems to display its own errors just fine by default.
54 init_connection($link);
56 if ($op == "-feeds") {
57 // Update all feeds needing a update.
58 update_daemon_common($link);
61 if ($op == "-feedbrowser") {
62 $count = update_feedbrowser_cache($link);
63 print "Finished, $count feeds processed.\n";
66 if ($op == "-daemon") {
68 passthru(PHP_EXECUTABLE
. " " . $argv[0] . " -daemon-loop");
69 _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL
. " seconds...");
70 sleep(DAEMON_SLEEP_INTERVAL
);
74 if ($op == "-daemon-loop") {
75 if (!make_stampfile('update_daemon.stamp')) {
76 die("error: unable to create stampfile\n");
79 // Call to the feed batch update function
80 // or regenerate feedbrowser cache
82 if (rand(0,100) > 30) {
83 update_daemon_common($link);
85 $count = update_feedbrowser_cache($link);
86 _debug("Feedbrowser updated, $count feeds processed.");
88 purge_orphans($link, true);
90 $rc = cleanup_tags($link, 14, 50000);
92 _debug("Cleaned $rc cached tags.");
97 if ($op == "-cleanup-tags") {
98 $rc = cleanup_tags($link, 14, 50000);
99 print "$rc tags deleted.\n";
104 unlink(LOCK_DIRECTORY
. "/$lock_filename");