Skip to content

Commit

Permalink
Merge pull request #115 from vpapaloukas/master
Browse files Browse the repository at this point in the history
add support for CURLOPT_CONNECTTIMEOUT
  • Loading branch information
sgiehl authored Mar 24, 2023
2 parents 23cea26 + 390a90d commit c9e7816
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions MatomoTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public function __construct($idSite, $apiUrl = '')

// Allow debug while blocking the request
$this->requestTimeout = 600;
$this->requestConnectTimeout = 300;
$this->doBulkRequests = false;
$this->storedTrackingActions = [];

Expand Down Expand Up @@ -1697,6 +1698,32 @@ public function setRequestTimeout($timeout)
return $this;
}

/**
* Returns the maximum number of seconds the tracker will spend trying to connect to Matomo.
* Defaults to 300 seconds.
*/
public function getRequestConnectTimeout()
{
return $this->requestConnectTimeout;
}

/**
* Sets the maximum number of seconds that the tracker will spend tryint to connect to Matomo.
*
* @param int $timeout
* @return $this
* @throws Exception
*/
public function setRequestConnectTimeout($timeout)
{
if (!is_int($timeout) || $timeout < 0) {
throw new Exception("Invalid value supplied for request connect timeout: $timeout");
}

$this->requestConnectTimeout = $timeout;
return $this;
}

/**
* Sets the request method to POST, which is recommended when using setTokenAuth()
* to prevent the token from being recorded in server logs. Avoid using redirects
Expand Down Expand Up @@ -1752,6 +1779,7 @@ protected function prepareCurlOptions($url, $method, $data, $forcePostUrlEncoded
CURLOPT_USERAGENT => $this->userAgent,
CURLOPT_HEADER => true,
CURLOPT_TIMEOUT => $this->requestTimeout,
CURLOPT_CONNECTTIMEOUT => $this->requestConnectTimeout,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array(
'Accept-Language: ' . $this->acceptLanguage,
Expand Down

0 comments on commit c9e7816

Please sign in to comment.