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