Pumpio: Improved Timeout check #322

Merged
annando merged 2 commits from 1511-pumpio-timeout into master 2015-11-03 07:17:56 +01:00
2 changed files with 40 additions and 8 deletions

View file

@ -998,6 +998,8 @@ class oauth_client_class
$this->response_status = 0; $this->response_status = 0;
$http = new http_class; $http = new http_class;
$http->debug = ($this->debug && $this->debug_http); $http->debug = ($this->debug && $this->debug_http);
$http->timeout = 30;
$http->data_timeout = 60;
$http->log_debug = true; $http->log_debug = true;
$http->sasl_authenticate = 0; $http->sasl_authenticate = 0;
$http->user_agent = $this->oauth_user_agent; $http->user_agent = $this->oauth_user_agent;

View file

@ -499,7 +499,10 @@ function pumpio_send(&$a,&$b) {
$username = $user.'@'.$host; $username = $user.'@'.$host;
$url = 'https://'.$host.'/api/user/'.$user.'/feed'; $url = 'https://'.$host.'/api/user/'.$user.'/feed';
if (pumpio_reachable($url))
$success = $client->CallAPI($url, 'POST', $params, array('FailOnAccessError'=>true, 'RequestContentType'=>'application/json'), $user); $success = $client->CallAPI($url, 'POST', $params, array('FailOnAccessError'=>true, 'RequestContentType'=>'application/json'), $user);
else
$success = false;
if($success) { if($success) {
@ -585,7 +588,10 @@ function pumpio_action(&$a, $uid, $uri, $action, $content = "") {
$url = 'https://'.$hostname.'/api/user/'.$username.'/feed'; $url = 'https://'.$hostname.'/api/user/'.$username.'/feed';
if (pumpio_reachable($url))
$success = $client->CallAPI($url, 'POST', $params, array('FailOnAccessError'=>true, 'RequestContentType'=>'application/json'), $user); $success = $client->CallAPI($url, 'POST', $params, array('FailOnAccessError'=>true, 'RequestContentType'=>'application/json'), $user);
else
$success = false;
if($success) if($success)
logger('pumpio_action '.$username.' '.$action.': success '.$uri); logger('pumpio_action '.$username.' '.$action.': success '.$uri);
@ -713,7 +719,10 @@ function pumpio_fetchtimeline(&$a, $uid) {
$username = $user.'@'.$host; $username = $user.'@'.$host;
if (pumpio_reachable($url))
$success = $client->CallAPI($url, 'GET', array(), array('FailOnAccessError'=>true), $user); $success = $client->CallAPI($url, 'GET', array(), array('FailOnAccessError'=>true), $user);
else
$success = false;
if (!$success) { if (!$success) {
logger('pumpio: error fetching posts for user '.$uid." ".$username." ".print_r($user, true)); 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 != "") if ($last_id != "")
$url .= '?since='.urlencode($last_id); $url .= '?since='.urlencode($last_id);
if (pumpio_reachable($url))
$success = $client->CallAPI($url, 'GET', array(), array('FailOnAccessError'=>true), $user); $success = $client->CallAPI($url, 'GET', array(), array('FailOnAccessError'=>true), $user);
else
$success = false;
if ($user->items) { if ($user->items) {
$posts = array_reverse($user->items); $posts = array_reverse($user->items);
@ -1409,12 +1421,18 @@ function pumpio_getallusers(&$a, $uid) {
$url = 'https://'.$hostname.'/api/user/'.$username.'/following'; $url = 'https://'.$hostname.'/api/user/'.$username.'/following';
if (pumpio_reachable($url))
$success = $client->CallAPI($url, 'GET', array(), array('FailOnAccessError'=>true), $users); $success = $client->CallAPI($url, 'GET', array(), array('FailOnAccessError'=>true), $users);
else
$success = false;
if ($users->totalItems > count($users->items)) { if ($users->totalItems > count($users->items)) {
$url = 'https://'.$hostname.'/api/user/'.$username.'/following?count='.$users->totalItems; $url = 'https://'.$hostname.'/api/user/'.$username.'/following?count='.$users->totalItems;
if (pumpio_reachable($url))
$success = $client->CallAPI($url, 'GET', array(), array('FailOnAccessError'=>true), $users); $success = $client->CallAPI($url, 'GET', array(), array('FailOnAccessError'=>true), $users);
else
$success = false;
} }
foreach ($users->items AS $user) foreach ($users->items AS $user)
@ -1475,7 +1493,10 @@ function pumpio_queue_hook(&$a,&$b) {
$client->client_id = $consumer_key; $client->client_id = $consumer_key;
$client->client_secret = $consumer_secret; $client->client_secret = $consumer_secret;
if (pumpio_reachable($z['url']))
$success = $client->CallAPI($z['url'], 'POST', $z['post'], array('FailOnAccessError'=>true, 'RequestContentType'=>'application/json'), $user); $success = $client->CallAPI($z['url'], 'POST', $z['post'], array('FailOnAccessError'=>true, 'RequestContentType'=>'application/json'), $user);
else
$success = false;
if($success) { if($success) {
$post_id = $user->object->id; $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); logger("pumpio_fetchallcomments: fetching comment for user ".$uid." url ".$url);
if (pumpio_reachable($url))
$success = $client->CallAPI($url, 'GET', array(), array('FailOnAccessError'=>true), $item); $success = $client->CallAPI($url, 'GET', array(), array('FailOnAccessError'=>true), $item);
else
$success = false;
if (!$success) if (!$success)
return; return;
@ -1688,6 +1712,12 @@ function pumpio_fetchallcomments(&$a, $uid, $id) {
} }
} }
function pumpio_reachable($url) {
$data = z_fetch_url($url, false, $redirects, array('timeout'=>10));
return(intval($data['return_code']) != 0);
}
/* /*
To-Do: To-Do:
- edit own notes - edit own notes