diff options
author | Andrew Dolgov <[email protected]> | 2005-12-03 15:25:40 +0100 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2005-12-03 15:25:40 +0100 |
commit | 1f2b01ed8ee1a7934be8d4ea4e7bfc2980910e3a (patch) | |
tree | 4fd86bf07603540a52b63e6c80101f026749da16 | |
parent | 8fe19cd81eae2b5a59652135e11463620b02419c (diff) |
update_feeds.php for CLI
-rw-r--r-- | config.php-dist | 3 | ||||
-rw-r--r-- | functions.php | 5 | ||||
-rw-r--r-- | update_feeds.php | 38 |
3 files changed, 43 insertions, 3 deletions
diff --git a/config.php-dist b/config.php-dist index 56a554106..00b47bfcc 100644 --- a/config.php-dist +++ b/config.php-dist @@ -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 diff --git a/functions.php b/functions.php index 6b6060573..ba80bab94 100644 --- a/functions.php +++ b/functions.php @@ -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; @@ -115,7 +114,7 @@ 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 index 000000000..38940896f --- /dev/null +++ b/update_feeds.php @@ -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); + +?> |