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