Skip to content

Commit c8f05f3

Browse files
author
Tim Helfensdörfer
authored
Merge pull request #44 from bashilbers/master
Make connection timeout configurable
2 parents cc5c277 + 80712eb commit c8f05f3

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/Matomo.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ class Matomo
9898
*/
9999
private $_maxRedirects = 5;
100100

101+
/**
102+
* @var null|int Maximum number of seconds the request might take
103+
*/
104+
private $_connectionTimeout = 5;
105+
101106
/**
102107
* Create a new instance.
103108
*
@@ -448,6 +453,29 @@ public function setMaxRedirects(int $maxRedirects): Matomo
448453
return $this;
449454
}
450455

456+
/**
457+
* How many seconds until the request errors.
458+
*
459+
* @return null|int
460+
*/
461+
public function getConnectionTimeout(): ?int
462+
{
463+
return $this->_connectionTimeout;
464+
}
465+
466+
/**
467+
* Set how many seconds until the request errors.
468+
*
469+
* @param null|int $connectionTimeout
470+
* @return Matomo
471+
*/
472+
public function setConnectionTimeout(?int $connectionTimeout = null): Matomo
473+
{
474+
$this->_connectionTimeout = $connectionTimeout;
475+
476+
return $this;
477+
}
478+
451479
/**
452480
* Reset all default variables.
453481
*/
@@ -484,7 +512,10 @@ private function _request(string $method, array $params = [], array $optional =
484512
$req = Request::get($url);
485513
$req->strict_ssl = $this->_verifySsl;
486514
$req->max_redirects = $this->_maxRedirects;
487-
$req->setConnectionTimeout(5);
515+
516+
if (is_int($this->getConnectionTimeout())) {
517+
$req->setConnectionTimeout($this->getConnectionTimeout());
518+
}
488519

489520
try {
490521
$buffer = $req->send();

0 commit comments

Comments
 (0)