]>
git.wh0rd.org - tt-rss.git/blob - update.php
3 set_include_path(get_include_path() . PATH_SEPARATOR
.
4 dirname(__FILE__
) . "/include");
6 define('DISABLE_SESSIONS', true);
8 chdir(dirname(__FILE__
));
10 require_once "functions.php";
11 require_once "rssfuncs.php";
12 require_once "sanity_check.php";
13 require_once "config.php";
14 require_once "db.php";
15 require_once "db-prefs.php";
17 if (!defined('PHP_EXECUTABLE'))
18 define('PHP_EXECUTABLE', '/usr/bin/php');
22 if (!$op ||
$op == "-help") {
23 print "Tiny Tiny RSS data update script.\n\n";
25 print " -feeds - update feeds\n";
26 print " -feedbrowser - update feedbrowser\n";
27 print " -daemon - start single-process update daemon\n";
28 print " -cleanup-tags - perform tags table maintenance\n";
29 print " -get-feeds - receive popular feeds from linked instances\n";
30 print " -help - show this help\n";
34 if ($op != "-daemon") {
35 $lock_filename = "update.lock";
37 $lock_filename = "update_daemon.lock";
40 $lock_handle = make_lockfile($lock_filename);
43 // Try to lock a file in order to avoid concurrent update.
45 die("error: Can't create lockfile ($lock_filename). ".
46 "Maybe another update process is already running.\n");
49 // Create a database connection.
50 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
52 init_connection($link);
54 if ($op == "-feeds") {
55 // Update all feeds needing a update.
56 update_daemon_common($link);
59 $count = update_feedbrowser_cache($link);
60 _debug("Feedbrowser updated, $count feeds processed.");
62 // Purge orphans and cleanup tags
63 purge_orphans($link, true);
65 $rc = cleanup_tags($link, 14, 50000);
66 _debug("Cleaned $rc cached tags.");
68 get_linked_feeds($link);
71 if ($op == "-feedbrowser") {
72 $count = update_feedbrowser_cache($link);
73 print "Finished, $count feeds processed.\n";
76 if ($op == "-daemon") {
78 passthru(PHP_EXECUTABLE
. " " . $argv[0] . " -daemon-loop");
79 _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL
. " seconds...");
80 sleep(DAEMON_SLEEP_INTERVAL
);
84 if ($op == "-daemon-loop") {
85 if (!make_stampfile('update_daemon.stamp')) {
86 die("error: unable to create stampfile\n");
89 // Call to the feed batch update function
90 // or regenerate feedbrowser cache
92 if (rand(0,100) > 30) {
93 update_daemon_common($link);
95 $count = update_feedbrowser_cache($link);
96 _debug("Feedbrowser updated, $count feeds processed.");
98 purge_orphans($link, true);
100 $rc = cleanup_tags($link, 14, 50000);
102 _debug("Cleaned $rc cached tags.");
104 get_linked_feeds($link);
109 if ($op == "-cleanup-tags") {
110 $rc = cleanup_tags($link, 14, 50000);
111 print "$rc tags deleted.\n";
114 if ($op == "-get-feeds") {
115 get_linked_feeds($link);
120 if ($lock_handle != false) {
121 fclose($lock_handle);
124 unlink(LOCK_DIRECTORY
. "/$lock_filename");