summaryrefslogtreecommitdiff
path: root/classes/rssutils.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2022-06-09 09:05:36 +0300
committerAndrew Dolgov <[email protected]>2022-06-09 09:06:52 +0300
commit2975c7297b680e486f326939b9fba82d8cf18035 (patch)
tree259e50fa137819332b804bcef231e8d7d307658b /classes/rssutils.php
parent7cd26272fac706f6a0b1bbc8b12ca1a8d2c5a0d9 (diff)
throttle updates if received HTTP 429 (Too Many Requests)
Diffstat (limited to 'classes/rssutils.php')
-rwxr-xr-xclasses/rssutils.php20
1 files changed, 19 insertions, 1 deletions
diff --git a/classes/rssutils.php b/classes/rssutils.php
index aec17d538..1d87e73d6 100755
--- a/classes/rssutils.php
+++ b/classes/rssutils.php
@@ -492,7 +492,7 @@ class RSSUtils {
// If-Modified-Since
if (UrlHelper::$fetch_last_error_code == 304) {
- Debug::log("source claims data not modified, nothing to do.", Debug::LOG_VERBOSE);
+ Debug::log("source claims data not modified (304), nothing to do.", Debug::LOG_VERBOSE);
$error_message = "";
$feed_obj->set([
@@ -503,6 +503,24 @@ class RSSUtils {
$feed_obj->save();
+ } else if (UrlHelper::$fetch_last_error_code == 429) {
+
+ // randomize interval using Config::HTTP_429_THROTTLE_INTERVAL as a base value (1-2x)
+ $http_429_throttle_interval = rand(Config::get(Config::HTTP_429_THROTTLE_INTERVAL),
+ Config::get(Config::HTTP_429_THROTTLE_INTERVAL)*2);
+
+ $error_message = UrlHelper::$fetch_last_error;
+
+ Debug::log("source claims we're requesting too often (429), throttling updates for $http_429_throttle_interval seconds.",
+ Debug::LOG_VERBOSE);
+
+ $feed_obj->set([
+ 'last_error' => $error_message . " (updates throttled for $http_429_throttle_interval seconds.)",
+ 'last_successful_update' => Db::NOW($http_429_throttle_interval),
+ 'last_updated' => Db::NOW($http_429_throttle_interval),
+ ]);
+
+ $feed_obj->save();
} else {
$error_message = UrlHelper::$fetch_last_error;