]>
git.wh0rd.org - tt-rss.git/blob - update.php
3 define('DISABLE_SESSIONS', true);
5 if (!defined('PHP_EXECUTABLE'))
6 define('PHP_EXECUTABLE', '/usr/bin/php');
8 require_once "functions.php";
9 require_once "sanity_check.php";
10 require_once "config.php";
11 require_once "db.php";
12 require_once "db-prefs.php";
16 if (!$op ||
$op == "-help") {
17 print "Tiny Tiny RSS data update script.\n\n";
19 print " -feeds - update feeds\n";
20 print " -feedbrowser - update feedbrowser\n";
21 print " -daemon - start single-process update daemon\n";
22 print " -cleanup-tags - perform tags table maintenance\n";
23 print " -help - show this help\n";
27 if ($op != "-daemon") {
28 $lock_filename = "update.lock";
30 $lock_filename = "update_daemon.lock";
33 $lock_handle = make_lockfile($lock_filename);
36 // Try to lock a file in order to avoid concurrent update.
38 die("error: Can't create lockfile ($lock_filename). ".
39 "Maybe another update process is already running.\n");
42 // Create a database connection.
43 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
46 if (DB_TYPE
== "mysql") {
49 // PG seems to display its own errors just fine by default.
53 init_connection($link);
55 if ($op == "-feeds") {
56 // Update all feeds needing a update.
57 update_daemon_common($link);
60 if ($op == "-feedbrowser") {
61 $count = update_feedbrowser_cache($link);
62 print "Finished, $count feeds processed.\n";
65 if ($op == "-daemon") {
66 if (!ENABLE_UPDATE_DAEMON
)
67 die("Please enable option ENABLE_UPDATE_DAEMON in config.php\n");
70 passthru(PHP_EXECUTABLE
. " " . $argv[0] . " -daemon-loop");
71 _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL
. " seconds...");
72 sleep(DAEMON_SLEEP_INTERVAL
);
76 if ($op == "-daemon-loop") {
77 if (!make_stampfile('update_daemon.stamp')) {
78 die("error: unable to create stampfile\n");
81 // Call to the feed batch update function
82 // or regenerate feedbrowser cache
84 if (rand(0,100) > 30) {
85 update_daemon_common($link);
87 $count = update_feedbrowser_cache($link);
88 _debug("Feedbrowser updated, $count feeds processed.");
90 purge_orphans($link, true);
92 $rc = cleanup_tags($link, 14, 50000);
94 _debug("Cleaned $rc cached tags.");
99 if ($op == "-cleanup-tags") {
100 $rc = cleanup_tags($link, 14, 50000);
101 print "$rc tags deleted.\n";
106 unlink(LOCK_DIRECTORY
. "/$lock_filename");