]> git.mxchange.org Git - friendica-addons.git/commitdiff
Pumpio: Timeout should now work
authorMichael Vogel <icarus@dabo.de>
Mon, 2 Nov 2015 23:42:04 +0000 (00:42 +0100)
committerMichael Vogel <icarus@dabo.de>
Mon, 2 Nov 2015 23:42:04 +0000 (00:42 +0100)
pumpio/oauth/oauth_client.php
pumpio/pumpio.php

index 2a709aab4e8025af9d0c4278708a521e465e4769..0e5fa4a58970fc82654973345940136b1c019992 100644 (file)
@@ -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;
index 491b3ffe2fec7d38410a0456fe78a83ab42a1a67..46c055a63d56ba920192511530415b2f21fac1ef 100644 (file)
@@ -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