]>
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 " -get-feeds - receive popular feeds from linked instances\n";
26 print " -help - show this help\n";
30 if ($op != "-daemon") {
31 $lock_filename = "update.lock";
33 $lock_filename = "update_daemon.lock";
36 $lock_handle = make_lockfile($lock_filename);
39 // Try to lock a file in order to avoid concurrent update.
41 die("error: Can't create lockfile ($lock_filename). ".
42 "Maybe another update process is already running.\n");
45 // Create a database connection.
46 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
49 if (DB_TYPE
== "mysql") {
52 // PG seems to display its own errors just fine by default.
56 init_connection($link);
58 if ($op == "-feeds") {
59 // Update all feeds needing a update.
60 update_daemon_common($link);
63 $count = update_feedbrowser_cache($link);
64 _debug("Feedbrowser updated, $count feeds processed.");
66 // Purge orphans and cleanup tags
67 purge_orphans($link, true);
69 $rc = cleanup_tags($link, 14, 50000);
70 _debug("Cleaned $rc cached tags.");
72 get_linked_feeds($link);
75 if ($op == "-feedbrowser") {
76 $count = update_feedbrowser_cache($link);
77 print "Finished, $count feeds processed.\n";
80 if ($op == "-daemon") {
82 passthru(PHP_EXECUTABLE
. " " . $argv[0] . " -daemon-loop");
83 _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL
. " seconds...");
84 sleep(DAEMON_SLEEP_INTERVAL
);
88 if ($op == "-daemon-loop") {
89 if (!make_stampfile('update_daemon.stamp')) {
90 die("error: unable to create stampfile\n");
93 // Call to the feed batch update function
94 // or regenerate feedbrowser cache
96 if (rand(0,100) > 30) {
97 update_daemon_common($link);
99 $count = update_feedbrowser_cache($link);
100 _debug("Feedbrowser updated, $count feeds processed.");
102 purge_orphans($link, true);
104 $rc = cleanup_tags($link, 14, 50000);
106 _debug("Cleaned $rc cached tags.");
108 get_linked_feeds($link);
113 if ($op == "-cleanup-tags") {
114 $rc = cleanup_tags($link, 14, 50000);
115 print "$rc tags deleted.\n";
118 if ($op == "-get-feeds") {
119 get_linked_feeds($link);
124 if ($lock_handle != false) {
125 fclose($lock_handle);
128 unlink(LOCK_DIRECTORY
. "/$lock_filename");