]>
git.wh0rd.org - tt-rss.git/blob - update.php
3 define('DISABLE_SESSIONS', true);
5 chdir(dirname(__FILE__
));
7 require_once "functions.php";
8 require_once "sanity_check.php";
9 require_once "config.php";
10 require_once "db.php";
11 require_once "db-prefs.php";
13 if (!defined('PHP_EXECUTABLE'))
14 define('PHP_EXECUTABLE', '/usr/bin/php');
18 if (!$op ||
$op == "-help") {
19 print "Tiny Tiny RSS data update script.\n\n";
21 print " -feeds - update feeds\n";
22 print " -feedbrowser - update feedbrowser\n";
23 print " -daemon - start single-process update daemon\n";
24 print " -cleanup-tags - perform tags table maintenance\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 $count = update_feedbrowser_cache($link);
63 _debug("Feedbrowser updated, $count feeds processed.");
65 // Purge orphans and cleanup tags
66 purge_orphans($link, true);
68 $rc = cleanup_tags($link, 14, 50000);
69 _debug("Cleaned $rc cached tags.");
72 if ($op == "-feedbrowser") {
73 $count = update_feedbrowser_cache($link);
74 print "Finished, $count feeds processed.\n";
77 if ($op == "-daemon") {
79 passthru(PHP_EXECUTABLE
. " " . $argv[0] . " -daemon-loop");
80 _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL
. " seconds...");
81 sleep(DAEMON_SLEEP_INTERVAL
);
85 if ($op == "-daemon-loop") {
86 if (!make_stampfile('update_daemon.stamp')) {
87 die("error: unable to create stampfile\n");
90 // Call to the feed batch update function
91 // or regenerate feedbrowser cache
93 if (rand(0,100) > 30) {
94 update_daemon_common($link);
96 $count = update_feedbrowser_cache($link);
97 _debug("Feedbrowser updated, $count feeds processed.");
99 purge_orphans($link, true);
101 $rc = cleanup_tags($link, 14, 50000);
103 _debug("Cleaned $rc cached tags.");
108 if ($op == "-cleanup-tags") {
109 $rc = cleanup_tags($link, 14, 50000);
110 print "$rc tags deleted.\n";
115 unlink(LOCK_DIRECTORY
. "/$lock_filename");