Skip to content

Commit 4e571ea

Browse files
authored
Merge pull request influxdata#105 from brycefranzen/guzzle_connect_timeout
Add ability to specify connect_timeout for guzzle
2 parents 4b8a0c9 + 9284521 commit 4e571ea

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

src/InfluxDB/Client.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ class Client
4848
*/
4949
protected $timeout = 0;
5050

51+
/**
52+
* @var float
53+
*/
54+
protected $connectTimeout = 0;
55+
5156
/**
5257
* @var bool
5358
*/
@@ -98,7 +103,8 @@ class Client
98103
* @param string $password
99104
* @param bool $ssl
100105
* @param bool $verifySSL
101-
* @param int $timeout
106+
* @param float $timeout
107+
* @param float $connectTimeout
102108
*/
103109
public function __construct(
104110
$host,
@@ -107,13 +113,15 @@ public function __construct(
107113
$password = '',
108114
$ssl = false,
109115
$verifySSL = false,
110-
$timeout = 0
116+
$timeout = 0,
117+
$connectTimeout = 0
111118
) {
112119
$this->host = (string) $host;
113120
$this->port = (int) $port;
114121
$this->username = (string) $username;
115122
$this->password = (string) $password;
116123
$this->timeout = (float) $timeout;
124+
$this->connectTimeout = (float) $connectTimeout;
117125
$this->verifySSL = (bool) $verifySSL;
118126

119127
if ($ssl) {
@@ -252,13 +260,14 @@ public function listUsers()
252260
* udp+influxdb://username:pass@localhost:4444/databasename
253261
*
254262
* @param string $dsn
255-
* @param int $timeout
263+
* @param float $timeout
256264
* @param bool $verifySSL
265+
* @param float $connectTimeout
257266
*
258267
* @return Client|Database
259268
* @throws ClientException
260269
*/
261-
public static function fromDSN($dsn, $timeout = 0, $verifySSL = false)
270+
public static function fromDSN($dsn, $timeout = 0, $verifySSL = false, $connectTimeout = 0)
262271
{
263272
$connParams = parse_url($dsn);
264273
$schemeInfo = explode('+', $connParams['scheme']);
@@ -285,7 +294,8 @@ public static function fromDSN($dsn, $timeout = 0, $verifySSL = false)
285294
isset($connParams['pass']) ? $connParams['pass'] : '',
286295
$ssl,
287296
$verifySSL,
288-
$timeout
297+
$timeout,
298+
$connectTimeout
289299
);
290300

291301
// set the UDP driver when the DSN specifies UDP
@@ -312,6 +322,14 @@ public function getTimeout()
312322
return $this->timeout;
313323
}
314324

325+
/**
326+
* @return float
327+
*/
328+
public function getConnectTimeout()
329+
{
330+
return $this->connectTimeout;
331+
}
332+
315333
/**
316334
* @return bool
317335
*/
@@ -341,6 +359,7 @@ public function getDriver()
341359
$this->driver = new Guzzle(
342360
new \GuzzleHttp\Client(
343361
[
362+
'connect_timeout' => $this->connectTimeout,
344363
'timeout' => $this->timeout,
345364
'base_uri' => $this->baseURI,
346365
'verify' => $this->verifySSL

0 commit comments

Comments
 (0)