]>
git.wh0rd.org - tt-rss.git/blob - update.php
3 set_include_path(get_include_path() . PATH_SEPARATOR
. "include");
5 define('DISABLE_SESSIONS', true);
7 chdir(dirname(__FILE__
));
9 require_once "functions.php";
10 require_once "sanity_check.php";
11 require_once "config.php";
12 require_once "db.php";
13 require_once "db-prefs.php";
15 if (!defined('PHP_EXECUTABLE'))
16 define('PHP_EXECUTABLE', '/usr/bin/php');
20 if (!$op ||
$op == "-help") {
21 print "Tiny Tiny RSS data update script.\n\n";
23 print " -feeds - update feeds\n";
24 print " -feedbrowser - update feedbrowser\n";
25 print " -daemon - start single-process update daemon\n";
26 print " -cleanup-tags - perform tags table maintenance\n";
27 print " -get-feeds - receive popular feeds from linked instances\n";
28 print " -help - show this help\n";
32 if ($op != "-daemon") {
33 $lock_filename = "update.lock";
35 $lock_filename = "update_daemon.lock";
38 $lock_handle = make_lockfile($lock_filename);
41 // Try to lock a file in order to avoid concurrent update.
43 die("error: Can't create lockfile ($lock_filename). ".
44 "Maybe another update process is already running.\n");
47 // Create a database connection.
48 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
50 init_connection($link);
52 if ($op == "-feeds") {
53 // Update all feeds needing a update.
54 update_daemon_common($link);
57 $count = update_feedbrowser_cache($link);
58 _debug("Feedbrowser updated, $count feeds processed.");
60 // Purge orphans and cleanup tags
61 purge_orphans($link, true);
63 $rc = cleanup_tags($link, 14, 50000);
64 _debug("Cleaned $rc cached tags.");
66 get_linked_feeds($link);
69 if ($op == "-feedbrowser") {
70 $count = update_feedbrowser_cache($link);
71 print "Finished, $count feeds processed.\n";
74 if ($op == "-daemon") {
76 passthru(PHP_EXECUTABLE
. " " . $argv[0] . " -daemon-loop");
77 _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL
. " seconds...");
78 sleep(DAEMON_SLEEP_INTERVAL
);
82 if ($op == "-daemon-loop") {
83 if (!make_stampfile('update_daemon.stamp')) {
84 die("error: unable to create stampfile\n");
87 // Call to the feed batch update function
88 // or regenerate feedbrowser cache
90 if (rand(0,100) > 30) {
91 update_daemon_common($link);
93 $count = update_feedbrowser_cache($link);
94 _debug("Feedbrowser updated, $count feeds processed.");
96 purge_orphans($link, true);
98 $rc = cleanup_tags($link, 14, 50000);
100 _debug("Cleaned $rc cached tags.");
102 get_linked_feeds($link);
107 if ($op == "-cleanup-tags") {
108 $rc = cleanup_tags($link, 14, 50000);
109 print "$rc tags deleted.\n";
112 if ($op == "-get-feeds") {
113 get_linked_feeds($link);
118 if ($lock_handle != false) {
119 fclose($lock_handle);
122 unlink(LOCK_DIRECTORY
. "/$lock_filename");