Skip to content

Commit

Permalink
Fix: Curl Connection remaining open (#133)
Browse files Browse the repository at this point in the history
* add curl_close and fix undefined variable

* change position of the curl_close

* 128 - wrap by try-finally block

* 128 - update changelog.md

---------

Co-authored-by: alutskevich <[email protected]>
  • Loading branch information
lutdev and alutskevich authored May 21, 2024
1 parent f1b9492 commit 92c2ce6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 21 additions & 17 deletions MatomoTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -2012,36 +2012,40 @@ 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);

$ch = curl_init();
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);

Expand Down

0 comments on commit 92c2ce6

Please sign in to comment.