Adding timeout options to curl
This commit is contained in:
parent
3c0b99efc9
commit
a439f98622
15
README.md
15
README.md
|
@ -55,3 +55,18 @@ foreach ($db->query("SELECT * FROM foo;") as $row) {
|
||||||
var_dump($row, $row->time);
|
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)
|
||||||
|
);
|
||||||
|
```
|
|
@ -44,6 +44,7 @@ class BaseHTTP
|
||||||
protected $user;
|
protected $user;
|
||||||
protected $pass;
|
protected $pass;
|
||||||
protected $base;
|
protected $base;
|
||||||
|
protected $timeout;
|
||||||
protected $timePrecision = 's';
|
protected $timePrecision = 's';
|
||||||
protected $children = array();
|
protected $children = array();
|
||||||
|
|
||||||
|
@ -60,6 +61,7 @@ class BaseHTTP
|
||||||
$this->pass = $c->pass;
|
$this->pass = $c->pass;
|
||||||
$this->port = $c->port;
|
$this->port = $c->port;
|
||||||
$this->host = $c->host;
|
$this->host = $c->host;
|
||||||
|
$this->timeout = $c->timeout;
|
||||||
$this->timePrecision = $c->timePrecision;
|
$this->timePrecision = $c->timePrecision;
|
||||||
$c->children[] = $this;
|
$c->children[] = $this;
|
||||||
}
|
}
|
||||||
|
@ -71,6 +73,9 @@ 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);
|
||||||
|
if($this->timeout !== null){
|
||||||
|
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
|
||||||
|
}
|
||||||
return $ch;
|
return $ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,13 +43,15 @@ class Client extends BaseHTTP
|
||||||
protected $port;
|
protected $port;
|
||||||
protected $user;
|
protected $user;
|
||||||
protected $pass;
|
protected $pass;
|
||||||
|
protected $timeout;
|
||||||
|
|
||||||
public function __construct($host = "localhost", $port = 8086, $u = 'root', $p = 'root')
|
public function __construct($host = "localhost", $port = 8086, $u = 'root', $p = 'root', $timeout = 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteDatabase($name)
|
public function deleteDatabase($name)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user