Browse Source

add 5-second timeout

master
Aaron Parecki 8 years ago
parent
commit
1c3735f634
No known key found for this signature in database GPG Key ID: 276C2817346D6056
2 changed files with 14 additions and 0 deletions
  1. +11
    -0
      lib/PushTask.php
  2. +3
    -0
      lib/request.php

+ 11
- 0
lib/PushTask.php View File

@ -81,9 +81,17 @@ class PushTask {
$feed = db\get_by_id('feeds', $feed_id); $feed = db\get_by_id('feeds', $feed_id);
if($feed) { 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 // 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); $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(); $feed->last_retrieved = db\now();
db\set_updated($feed); db\set_updated($feed);
$content_hash = md5($response['body']); $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"; 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()]); DeferredTask::queue('PushTask', 'notify_subscriber', [$feed_id, $s->id, db\now()]);
} }
if(count($subscribers) == 0) {
echo "No active subscribers\n";
}
} else { } else {
$feed->save(); $feed->save();

+ 3
- 0
lib/request.php View File

@ -6,6 +6,7 @@ function get_url($url, $include_headers=false) {
set_user_agent($ch); set_user_agent($ch);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
if($include_headers) { if($include_headers) {
curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_HEADER, true);
$response = curl_exec($ch); $response = curl_exec($ch);
@ -27,6 +28,7 @@ function get_head($url) {
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$headers = curl_exec($ch); $headers = curl_exec($ch);
return [ return [
'status' => curl_getinfo($ch, CURLINFO_HTTP_CODE), '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_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body); curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$response = curl_exec($ch); $response = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
return [ return [

Loading…
Cancel
Save