From f48b4ae53536b99e9127d3e2976b2f4530a76455 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 3 Nov 2015 00:42:04 +0100 Subject: [PATCH] Pumpio: Timeout should now work --- pumpio/oauth/oauth_client.php | 2 ++ pumpio/pumpio.php | 47 +++++++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/pumpio/oauth/oauth_client.php b/pumpio/oauth/oauth_client.php index 2a709aab..0e5fa4a5 100644 --- a/pumpio/oauth/oauth_client.php +++ b/pumpio/oauth/oauth_client.php @@ -998,6 +998,8 @@ class oauth_client_class $this->response_status = 0; $http = new http_class; $http->debug = ($this->debug && $this->debug_http); + $http->timeout = 30; + $http->data_timeout = 60; $http->log_debug = true; $http->sasl_authenticate = 0; $http->user_agent = $this->oauth_user_agent; diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index 491b3ffe..46c055a6 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -499,7 +499,10 @@ function pumpio_send(&$a,&$b) { $username = $user.'@'.$host; $url = 'https://'.$host.'/api/user/'.$user.'/feed'; - $success = $client->CallAPI($url, 'POST', $params, array('FailOnAccessError'=>true, 'RequestContentType'=>'application/json'), $user); + if (pumpio_reachable($url)) + $success = $client->CallAPI($url, 'POST', $params, array('FailOnAccessError'=>true, 'RequestContentType'=>'application/json'), $user); + else + $success = false; if($success) { @@ -585,7 +588,10 @@ function pumpio_action(&$a, $uid, $uri, $action, $content = "") { $url = 'https://'.$hostname.'/api/user/'.$username.'/feed'; - $success = $client->CallAPI($url, 'POST', $params, array('FailOnAccessError'=>true, 'RequestContentType'=>'application/json'), $user); + if (pumpio_reachable($url)) + $success = $client->CallAPI($url, 'POST', $params, array('FailOnAccessError'=>true, 'RequestContentType'=>'application/json'), $user); + else + $success = false; if($success) logger('pumpio_action '.$username.' '.$action.': success '.$uri); @@ -713,7 +719,10 @@ function pumpio_fetchtimeline(&$a, $uid) { $username = $user.'@'.$host; - $success = $client->CallAPI($url, 'GET', array(), array('FailOnAccessError'=>true), $user); + if (pumpio_reachable($url)) + $success = $client->CallAPI($url, 'GET', array(), array('FailOnAccessError'=>true), $user); + else + $success = false; if (!$success) { logger('pumpio: error fetching posts for user '.$uid." ".$username." ".print_r($user, true)); @@ -1371,7 +1380,10 @@ function pumpio_fetchinbox(&$a, $uid) { if ($last_id != "") $url .= '?since='.urlencode($last_id); - $success = $client->CallAPI($url, 'GET', array(), array('FailOnAccessError'=>true), $user); + if (pumpio_reachable($url)) + $success = $client->CallAPI($url, 'GET', array(), array('FailOnAccessError'=>true), $user); + else + $success = false; if ($user->items) { $posts = array_reverse($user->items); @@ -1409,12 +1421,18 @@ function pumpio_getallusers(&$a, $uid) { $url = 'https://'.$hostname.'/api/user/'.$username.'/following'; - $success = $client->CallAPI($url, 'GET', array(), array('FailOnAccessError'=>true), $users); + if (pumpio_reachable($url)) + $success = $client->CallAPI($url, 'GET', array(), array('FailOnAccessError'=>true), $users); + else + $success = false; if ($users->totalItems > count($users->items)) { $url = 'https://'.$hostname.'/api/user/'.$username.'/following?count='.$users->totalItems; - $success = $client->CallAPI($url, 'GET', array(), array('FailOnAccessError'=>true), $users); + if (pumpio_reachable($url)) + $success = $client->CallAPI($url, 'GET', array(), array('FailOnAccessError'=>true), $users); + else + $success = false; } foreach ($users->items AS $user) @@ -1475,7 +1493,10 @@ function pumpio_queue_hook(&$a,&$b) { $client->client_id = $consumer_key; $client->client_secret = $consumer_secret; - $success = $client->CallAPI($z['url'], 'POST', $z['post'], array('FailOnAccessError'=>true, 'RequestContentType'=>'application/json'), $user); + if (pumpio_reachable($z['url'])) + $success = $client->CallAPI($z['url'], 'POST', $z['post'], array('FailOnAccessError'=>true, 'RequestContentType'=>'application/json'), $user); + else + $success = false; if($success) { $post_id = $user->object->id; @@ -1623,7 +1644,10 @@ function pumpio_fetchallcomments(&$a, $uid, $id) { logger("pumpio_fetchallcomments: fetching comment for user ".$uid." url ".$url); - $success = $client->CallAPI($url, 'GET', array(), array('FailOnAccessError'=>true), $item); + if (pumpio_reachable($url)) + $success = $client->CallAPI($url, 'GET', array(), array('FailOnAccessError'=>true), $item); + else + $success = false; if (!$success) return; @@ -1688,6 +1712,13 @@ function pumpio_fetchallcomments(&$a, $uid, $id) { } } + +function pumpio_reachable($url) { + $data = z_fetch_url($url, false, $redirects, array('timeout'=>10)); + + return($data['success']); +} + /* To-Do: - edit own notes -- 2.39.5