From 830b11c64727b53637db8e65d7180f7ea1eaab23 Mon Sep 17 00:00:00 2001 From: Will Bradley Date: Fri, 20 Mar 2015 22:01:49 -0700 Subject: [PATCH] Adding connect timeout as well --- lib/InfluxPHP/BaseHTTP.php | 8 +++++++- lib/InfluxPHP/Client.php | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/InfluxPHP/BaseHTTP.php b/lib/InfluxPHP/BaseHTTP.php index b061a06..776b3f9 100644 --- a/lib/InfluxPHP/BaseHTTP.php +++ b/lib/InfluxPHP/BaseHTTP.php @@ -45,6 +45,7 @@ class BaseHTTP protected $pass; protected $base; protected $timeout; + protected $connectTimeout; protected $timePrecision = 's'; protected $children = array(); @@ -62,6 +63,7 @@ class BaseHTTP $this->port = $c->port; $this->host = $c->host; $this->timeout = $c->timeout; + $this->connectTimeout = $c->connectTimeout; $this->timePrecision = $c->timePrecision; $c->children[] = $this; } @@ -73,8 +75,12 @@ class BaseHTTP $url .= "?" . http_build_query($args); $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + var_dump($this->timeout); if($this->timeout !== null){ - curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout); + curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout); + } + if($this->connectTimeout !== null){ + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout); } return $ch; } diff --git a/lib/InfluxPHP/Client.php b/lib/InfluxPHP/Client.php index 87ef51a..fe079f4 100644 --- a/lib/InfluxPHP/Client.php +++ b/lib/InfluxPHP/Client.php @@ -44,14 +44,16 @@ class Client extends BaseHTTP protected $user; protected $pass; protected $timeout; + protected $connectTimeout; - public function __construct($host = "localhost", $port = 8086, $u = 'root', $p = 'root', $timeout = null) + public function __construct($host = "localhost", $port = 8086, $u = 'root', $p = 'root', $timeout = null, $connectTimeout = null) { $this->host = $host; $this->port = $port; $this->user = $u; $this->pass = $p; $this->timeout = $timeout; + $this->connectTimeout = $connectTimeout; } public function deleteDatabase($name)