Skip to content

Commit

Permalink
add support for CURLOPT_CONNECTTIMEOUT
Browse files Browse the repository at this point in the history
  • Loading branch information
vpapaloukas committed Mar 24, 2023
1 parent 23cea26 commit 949924c
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 0 seconds (unlimited).
*/
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 949924c

Please sign in to comment.