This is an automated email from the ASF dual-hosted git repository.

jensg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git

commit 0f21e39c9ba1b20a50d035f01c14836885678d08
Author: vladimir.panivko <[email protected]>
AuthorDate: Tue Jan 19 10:04:11 2021 +0200

    THRIFT-5336 Add possibility to setup connection timeout in TCurlClient
    Patch: Vladimir Panivko
    Client: php
    
    This closes #2306
---
 lib/php/lib/Transport/TCurlClient.php | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/lib/php/lib/Transport/TCurlClient.php 
b/lib/php/lib/Transport/TCurlClient.php
index f781da9..2087433 100644
--- a/lib/php/lib/Transport/TCurlClient.php
+++ b/lib/php/lib/Transport/TCurlClient.php
@@ -84,6 +84,13 @@ class TCurlClient extends TTransport
     protected $timeout_;
 
     /**
+     * Connection timeout
+     *
+     * @var float
+     */
+    protected $connectionTimeout_;
+
+    /**
      * http headers
      *
      * @var array
@@ -109,6 +116,7 @@ class TCurlClient extends TTransport
         $this->request_ = '';
         $this->response_ = null;
         $this->timeout_ = null;
+        $this->connectionTimeout_ = null;
         $this->headers_ = array();
     }
 
@@ -123,6 +131,16 @@ class TCurlClient extends TTransport
     }
 
     /**
+     * Set connection timeout
+     *
+     * @param float $connectionTimeout
+     */
+    public function setConnectionTimeoutSecs($connectionTimeout)
+    {
+        $this->connectionTimeout_ = $connectionTimeout;
+    }
+
+    /**
      * Whether this transport is open.
      *
      * @return boolean true if open
@@ -237,6 +255,14 @@ class TCurlClient extends TTransport
                 curl_setopt(self::$curlHandle, CURLOPT_TIMEOUT, 
$this->timeout_);
             }
         }
+        if ($this->connectionTimeout_ > 0) {
+            if ($this->connectionTimeout_ < 1.0) {
+                // Timestamps smaller than 1 second are ignored when 
CURLOPT_CONNECTTIMEOUT is used
+                curl_setopt(self::$curlHandle, CURLOPT_CONNECTTIMEOUT_MS, 1000 
* $this->connectionTimeout_);
+            } else {
+                curl_setopt(self::$curlHandle, CURLOPT_CONNECTTIMEOUT, 
$this->connectionTimeout_);
+            }
+        }
         curl_setopt(self::$curlHandle, CURLOPT_POSTFIELDS, $this->request_);
         $this->request_ = '';
 

Reply via email to