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