]> git.wh0rd.org Git - tt-rss.git/commitdiff
update_feeds.php for CLI
authorAndrew Dolgov <fox@bah.spb.su>
Sat, 3 Dec 2005 14:25:40 +0000 (15:25 +0100)
committerAndrew Dolgov <fox@bah.spb.su>
Sat, 3 Dec 2005 14:25:40 +0000 (15:25 +0100)
config.php-dist
functions.php
update_feeds.php [new file with mode: 0644]

index 56a554106ccd781b2d05563adb34c80ef99e8466..00b47bfcc839afd143fafc6c828b9117efdba68b 100644 (file)
@@ -39,6 +39,9 @@
        // */30 * * * * /usr/bin/wget -O /dev/null -T 600 "http://www.your-site.xxx/tt-rss/backend.php?op=globalUpdateFeeds&daemon=1"
        //
 
+       // The alternative approach is to run update_feeds.php from your crontab
+       // with command line PHP interpreter.
+
        define('SMART_RPC_COUNTERS', true);
        // If enabled, stores feed counter information on the server side and sends
        // only diffs to the client. In the nutshell, it saves your bandwidth and
index 6b606057338b47411f10ad755106f329d64dbf6c..ba80bab94da6914ac089a9eb2a865bcdb78722a5 100644 (file)
@@ -1,5 +1,4 @@
 <?
-       session_start();
 
        if ($_GET["debug"]) {
                define('DEFAULT_ERROR_LEVEL', E_ALL);
@@ -90,7 +89,7 @@
                        (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0");
        }
 
-       function update_all_feeds($link, $fetch, $user_id = false) {
+       function update_all_feeds($link, $fetch, $user_id = false, $force_daemon = false) {
 
                if (WEB_DEMO_MODE) return;
 
                        if ($fetch || (!$line["last_updated"] || 
                                time() - strtotime($line["last_updated"]) > ($upd_intl * 60))) {
 
-                               update_rss_feed($link, $line["feed_url"], $line["id"]);
+                               update_rss_feed($link, $line["feed_url"], $line["id"], $force_daemon);
                        }
                }
 
diff --git a/update_feeds.php b/update_feeds.php
new file mode 100644 (file)
index 0000000..3894089
--- /dev/null
@@ -0,0 +1,38 @@
+#!/usr/bin/php4
+
+<?
+       // this script is probably run not from your httpd-user, so cache
+       // directory defined in config.php won't be accessible
+       define('MAGPIE_CACHE_DIR', '/var/tmp/magpie-ttrss-cache-cli');
+
+       require_once "sanity_check.php";
+       require_once "config.php";
+       require_once "db.php";
+       require_once "db-prefs.php";
+       require_once "functions.php";
+       require_once "magpierss/rss_fetch.inc";
+
+       $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); 
+
+       if (!$link) {
+               if (DB_TYPE == "mysql") {
+                       print mysql_error();
+               }
+               // PG seems to display its own errors just fine by default.             
+               return;
+       }
+
+       if (DB_TYPE == "pgsql") {
+               pg_query("set client_encoding = 'utf-8'");
+       }
+
+       $result = db_query($link, "SELECT id FROM ttrss_users");
+
+       while ($line = db_fetch_assoc($result)) {
+                       $user_id = $line["id"];
+                       update_all_feeds($link, false, $user_id, true);
+       }
+
+       db_close($link);
+
+?>