Browse Source

add 5-second timeout

master
Aaron Parecki 5 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);
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();

+ 3
- 0
lib/request.php View File

@ -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 [

Loading…
Cancel
Save