Adding connect timeout as well

This commit is contained in:
Will Bradley 2015-03-20 22:01:49 -07:00
parent a439f98622
commit 830b11c647
2 changed files with 10 additions and 2 deletions

View File

@ -45,6 +45,7 @@ class BaseHTTP
protected $pass; protected $pass;
protected $base; protected $base;
protected $timeout; protected $timeout;
protected $connectTimeout;
protected $timePrecision = 's'; protected $timePrecision = 's';
protected $children = array(); protected $children = array();
@ -62,6 +63,7 @@ class BaseHTTP
$this->port = $c->port; $this->port = $c->port;
$this->host = $c->host; $this->host = $c->host;
$this->timeout = $c->timeout; $this->timeout = $c->timeout;
$this->connectTimeout = $c->connectTimeout;
$this->timePrecision = $c->timePrecision; $this->timePrecision = $c->timePrecision;
$c->children[] = $this; $c->children[] = $this;
} }
@ -73,9 +75,13 @@ class BaseHTTP
$url .= "?" . http_build_query($args); $url .= "?" . http_build_query($args);
$ch = curl_init($url); $ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
var_dump($this->timeout);
if($this->timeout !== null){ 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; return $ch;
} }

View File

@ -44,14 +44,16 @@ class Client extends BaseHTTP
protected $user; protected $user;
protected $pass; protected $pass;
protected $timeout; 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->host = $host;
$this->port = $port; $this->port = $port;
$this->user = $u; $this->user = $u;
$this->pass = $p; $this->pass = $p;
$this->timeout = $timeout; $this->timeout = $timeout;
$this->connectTimeout = $connectTimeout;
} }
public function deleteDatabase($name) public function deleteDatabase($name)