diff --git a/lib/PushTask.php b/lib/PushTask.php index d44c587..0af2730 100644 --- a/lib/PushTask.php +++ b/lib/PushTask.php @@ -81,9 +81,17 @@ class PushTask { $feed = db\get_by_id('feeds', $feed_id); if($feed) { + echo $feed->feed_url."\n"; + echo "Checking feed for updates...\n"; + // First check the feed to see if the content has changed since the last time we checked $response = request\get_url($feed->feed_url, true); + if($response['code'] != 200) { + echo "Feed did not return HTTP 200: ".$response['code'].". Skipping publish.\n"; + return; + } + $feed->last_retrieved = db\now(); db\set_updated($feed); $content_hash = md5($response['body']); @@ -103,6 +111,9 @@ class PushTask { echo "Queuing notification for feed_id=$feed_id ($feed->feed_url) subscription_id=$s->id ($s->callback_url)\n"; DeferredTask::queue('PushTask', 'notify_subscriber', [$feed_id, $s->id, db\now()]); } + if(count($subscribers) == 0) { + echo "No active subscribers\n"; + } } else { $feed->save(); diff --git a/lib/request.php b/lib/request.php index 1775ec4..cd3c3b2 100644 --- a/lib/request.php +++ b/lib/request.php @@ -6,6 +6,7 @@ function get_url($url, $include_headers=false) { set_user_agent($ch); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_TIMEOUT, 5); if($include_headers) { curl_setopt($ch, CURLOPT_HEADER, true); $response = curl_exec($ch); @@ -27,6 +28,7 @@ function get_head($url) { curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_NOBODY, true); + curl_setopt($ch, CURLOPT_TIMEOUT, 5); $headers = curl_exec($ch); return [ 'status' => curl_getinfo($ch, CURLINFO_HTTP_CODE), @@ -51,6 +53,7 @@ function post($url, $params, $format='form', $headers=[]) { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $body); curl_setopt($ch, CURLOPT_HEADER, true); + curl_setopt($ch, CURLOPT_TIMEOUT, 5); $response = curl_exec($ch); $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); return [