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