]>
Commit | Line | Data |
---|---|---|
661135c7 | 1 | #!/usr/bin/php |
fecd57c8 | 2 | <?php |
661135c7 AD |
3 | define('DISABLE_SESSIONS', true); |
4 | ||
d1950553 | 5 | chdir(dirname($_SERVER['SCRIPT_NAME'])); |
fb074239 | 6 | require_once "functions.php"; |
81596c66 | 7 | require_once "sanity_check.php"; |
81596c66 AD |
8 | require_once "config.php"; |
9 | require_once "db.php"; | |
661135c7 | 10 | require_once "db-prefs.php"; |
661135c7 | 11 | |
86268d8b AD |
12 | if (!defined('PHP_EXECUTABLE')) |
13 | define('PHP_EXECUTABLE', '/usr/bin/php'); | |
14 | ||
661135c7 | 15 | $op = $argv[1]; |
70dcff6b | 16 | |
661135c7 AD |
17 | if (!$op || $op == "-help") { |
18 | print "Tiny Tiny RSS data update script.\n\n"; | |
19 | print "Options:\n"; | |
20 | print " -feeds - update feeds\n"; | |
21 | print " -feedbrowser - update feedbrowser\n"; | |
22 | print " -daemon - start single-process update daemon\n"; | |
868650e4 | 23 | print " -cleanup-tags - perform tags table maintenance\n"; |
661135c7 AD |
24 | print " -help - show this help\n"; |
25 | return; | |
81596c66 | 26 | } |
87b9fb65 | 27 | |
661135c7 AD |
28 | if ($op != "-daemon") { |
29 | $lock_filename = "update.lock"; | |
30 | } else { | |
31 | $lock_filename = "update_daemon.lock"; | |
32 | } | |
fecd57c8 | 33 | |
661135c7 AD |
34 | $lock_handle = make_lockfile($lock_filename); |
35 | $must_exit = false; | |
fecd57c8 | 36 | |
661135c7 AD |
37 | // Try to lock a file in order to avoid concurrent update. |
38 | if (!$lock_handle) { | |
39 | die("error: Can't create lockfile ($lock_filename). ". | |
40 | "Maybe another update process is already running.\n"); | |
41 | } | |
fecd57c8 | 42 | |
661135c7 | 43 | // Create a database connection. |
dbaa4e4a | 44 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); |
fecd57c8 | 45 | |
661135c7 AD |
46 | if (!$link) { |
47 | if (DB_TYPE == "mysql") { | |
48 | print mysql_error(); | |
49 | } | |
dbaa4e4a | 50 | // PG seems to display its own errors just fine by default. |
661135c7 AD |
51 | return; |
52 | } | |
b4c27af7 | 53 | |
661135c7 | 54 | init_connection($link); |
ef59e6e8 | 55 | |
661135c7 AD |
56 | if ($op == "-feeds") { |
57 | // Update all feeds needing a update. | |
58 | update_daemon_common($link); | |
59 | } | |
fecd57c8 | 60 | |
661135c7 AD |
61 | if ($op == "-feedbrowser") { |
62 | $count = update_feedbrowser_cache($link); | |
63 | print "Finished, $count feeds processed.\n"; | |
fecd57c8 | 64 | } |
661135c7 AD |
65 | |
66 | if ($op == "-daemon") { | |
661135c7 AD |
67 | while (true) { |
68 | passthru(PHP_EXECUTABLE . " " . $argv[0] . " -daemon-loop"); | |
69 | _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL . " seconds..."); | |
70 | sleep(DAEMON_SLEEP_INTERVAL); | |
fecd57c8 | 71 | } |
81596c66 | 72 | } |
9e21a571 | 73 | |
661135c7 AD |
74 | if ($op == "-daemon-loop") { |
75 | if (!make_stampfile('update_daemon.stamp')) { | |
76 | die("error: unable to create stampfile\n"); | |
77 | } | |
9e21a571 | 78 | |
dbaa4e4a | 79 | // Call to the feed batch update function |
661135c7 | 80 | // or regenerate feedbrowser cache |
9e21a571 | 81 | |
661135c7 AD |
82 | if (rand(0,100) > 30) { |
83 | update_daemon_common($link); | |
9e21a571 | 84 | } else { |
661135c7 | 85 | $count = update_feedbrowser_cache($link); |
e3b42c5a AD |
86 | _debug("Feedbrowser updated, $count feeds processed."); |
87 | ||
88 | purge_orphans($link, true); | |
dbaa4e4a | 89 | |
e3b42c5a AD |
90 | $rc = cleanup_tags($link, 14, 50000); |
91 | ||
92 | _debug("Cleaned $rc cached tags."); | |
9e21a571 | 93 | } |
ef59e6e8 | 94 | |
fecd57c8 | 95 | } |
fecd57c8 | 96 | |
868650e4 AD |
97 | if ($op == "-cleanup-tags") { |
98 | $rc = cleanup_tags($link, 14, 50000); | |
99 | print "$rc tags deleted.\n"; | |
100 | } | |
101 | ||
661135c7 | 102 | db_close($link); |
fecd57c8 | 103 | |
661135c7 AD |
104 | unlink(LOCK_DIRECTORY . "/$lock_filename"); |
105 | ?> |