Compare commits

..

3 Commits

Author SHA1 Message Date
db57639b48 Removing debug 2015-03-20 22:20:15 -07:00
830b11c647 Adding connect timeout as well 2015-03-20 22:01:49 -07:00
a439f98622 Adding timeout options to curl 2015-02-28 13:59:45 -07:00
3 changed files with 30 additions and 1 deletions

View File

@ -55,3 +55,18 @@ foreach ($db->query("SELECT * FROM foo;") as $row) {
var_dump($row, $row->time);
}
```
Options
-------
- **Timeout** to prevent slow queries from hanging your program:
```php
$client = new \crodas\InfluxPHP\Client(
"localhost" /*default*/,
8086 /* default */,
"root" /* by default */,
"root" /* by default */,
60 // 60-second timeout (CURLOPT_TIMEOUT)
);
```

View File

@ -44,6 +44,8 @@ class BaseHTTP
protected $user;
protected $pass;
protected $base;
protected $timeout;
protected $connectTimeout;
protected $timePrecision = 's';
protected $children = array();
@ -60,6 +62,8 @@ class BaseHTTP
$this->pass = $c->pass;
$this->port = $c->port;
$this->host = $c->host;
$this->timeout = $c->timeout;
$this->connectTimeout = $c->connectTimeout;
$this->timePrecision = $c->timePrecision;
$c->children[] = $this;
}
@ -71,6 +75,12 @@ class BaseHTTP
$url .= "?" . http_build_query($args);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if($this->timeout !== null){
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
}
if($this->connectTimeout !== null){
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
}
return $ch;
}

View File

@ -43,13 +43,17 @@ class Client extends BaseHTTP
protected $port;
protected $user;
protected $pass;
protected $timeout;
protected $connectTimeout;
public function __construct($host = "localhost", $port = 8086, $u = 'root', $p = 'root')
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)