Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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