diff options
author | vladimir.panivko <vladimir.panivko@together.com> | 2021-01-19 10:04:11 +0200 |
---|---|---|
committer | Jens Geyer <jensg@apache.org> | 2021-01-24 12:33:48 +0100 |
commit | 0f21e39c9ba1b20a50d035f01c14836885678d08 (patch) | |
tree | 60023ec4365d16f326f5d6eb89fd3e37cd5857fb | |
parent | bee96a1ff02d682c955707406f21164cd8d66552 (diff) | |
download | thrift-0f21e39c9ba1b20a50d035f01c14836885678d08.tar.gz |
THRIFT-5336 Add possibility to setup connection timeout in TCurlClient
Patch: Vladimir Panivko
Client: php
This closes #2306
-rw-r--r-- | lib/php/lib/Transport/TCurlClient.php | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/php/lib/Transport/TCurlClient.php b/lib/php/lib/Transport/TCurlClient.php index f781da969..2087433dd 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_ = ''; |