]> git.wh0rd.org - tt-rss.git/blame - update.php
subscribetofeed: handle server error/wrong output properly
[tt-rss.git] / update.php
CommitLineData
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";
22 print " -help - show this help\n";
23 return;
81596c66 24 }
87b9fb65 25
661135c7
AD
26 if ($op != "-daemon") {
27 $lock_filename = "update.lock";
28 } else {
29 $lock_filename = "update_daemon.lock";
30 }
fecd57c8 31
661135c7
AD
32 $lock_handle = make_lockfile($lock_filename);
33 $must_exit = false;
fecd57c8 34
661135c7
AD
35 // Try to lock a file in order to avoid concurrent update.
36 if (!$lock_handle) {
37 die("error: Can't create lockfile ($lock_filename). ".
38 "Maybe another update process is already running.\n");
39 }
fecd57c8 40
661135c7
AD
41 // Create a database connection.
42 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
fecd57c8 43
661135c7
AD
44 if (!$link) {
45 if (DB_TYPE == "mysql") {
46 print mysql_error();
47 }
48 // PG seems to display its own errors just fine by default.
49 return;
50 }
b4c27af7 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);
57 }
fecd57c8 58
661135c7
AD
59 if ($op == "-feedbrowser") {
60 $count = update_feedbrowser_cache($link);
61 print "Finished, $count feeds processed.\n";
fecd57c8 62 }
661135c7
AD
63
64 if ($op == "-daemon") {
65 if (!ENABLE_UPDATE_DAEMON)
66 die("Please enable option ENABLE_UPDATE_DAEMON in config.php\n");
67
68 while (true) {
69 passthru(PHP_EXECUTABLE . " " . $argv[0] . " -daemon-loop");
70 _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL . " seconds...");
71 sleep(DAEMON_SLEEP_INTERVAL);
fecd57c8 72 }
81596c66 73 }
9e21a571 74
661135c7
AD
75 if ($op == "-daemon-loop") {
76 if (!make_stampfile('update_daemon.stamp')) {
77 die("error: unable to create stampfile\n");
78 }
9e21a571 79
661135c7
AD
80 // Call to the feed batch update function
81 // or regenerate feedbrowser cache
9e21a571 82
661135c7
AD
83 if (rand(0,100) > 30) {
84 update_daemon_common($link);
9e21a571 85 } else {
661135c7
AD
86 $count = update_feedbrowser_cache($link);
87 _debug("Finished, $count feeds processed.");
9e21a571 88 }
ef59e6e8 89
fecd57c8 90 }
fecd57c8 91
661135c7 92 db_close($link);
fecd57c8 93
661135c7
AD
94 unlink(LOCK_DIRECTORY . "/$lock_filename");
95?>