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