diff --git a/CHANGELOG.md b/CHANGELOG.md index fcb693e..5afde19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ This is the Developer Changelog for Matomo PHP Tracker. All breaking changes or new features are listed below. +## Matomo PHP Tracker 3.3.1 +### Fixed +- closed curl connection + ## Matomo PHP Tracker 3.3.0 ### Removed - support for PHP versions lower than 7.2 diff --git a/MatomoTracker.php b/MatomoTracker.php index 7b65ace..234c6bf 100644 --- a/MatomoTracker.php +++ b/MatomoTracker.php @@ -2012,6 +2012,8 @@ protected function sendRequest($url, $method = 'GET', $data = null, $force = fal } } + $content = ''; + if (function_exists('curl_init') && function_exists('curl_exec')) { $options = $this->prepareCurlOptions($url, $method, $data, $forcePostUrlEncoded); @@ -2019,29 +2021,31 @@ protected function sendRequest($url, $method = 'GET', $data = null, $force = fal curl_setopt_array($ch, $options); ob_start(); $response = @curl_exec($ch); - ob_end_clean(); - $header = ''; - $content = ''; + try { + $header = ''; - if ($response === false) { - $curlError = curl_error($ch); - if (!empty($curlError)) { - throw new \RuntimeException($curlError); + if ($response === false) { + $curlError = curl_error($ch); + if (!empty($curlError)) { + throw new \RuntimeException($curlError); + } } - } - - if (!empty($response)) { - // extract header - $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE); - $header = substr($response, 0, $headerSize); - // extract content - $content = substr($response, $headerSize); - } + if (!empty($response)) { + // extract header + $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE); + $header = substr($response, 0, $headerSize); - $this->parseIncomingCookies(explode("\r\n", $header)); + // extract content + $content = substr($response, $headerSize); + } + $this->parseIncomingCookies(explode("\r\n", $header)); + } finally { + curl_close($ch); + ob_end_clean(); + } } elseif (function_exists('stream_context_create')) { $stream_options = $this->prepareStreamOptions($method, $data, $forcePostUrlEncoded);