From a15c5f5201e60a2f6792d13b6b75e4fc2bc9a854 Mon Sep 17 00:00:00 2001 From: nguyenanhung Date: Sun, 17 May 2026 00:26:55 +0700 Subject: [PATCH] Fix curl_close --- helpers/ip_helper.php | 4 +++- helpers/request_helper.php | 4 +++- src/BaseHelper.php | 4 ++-- src/BasicCurl.php | 2 +- src/SimpleCurl.php | 4 +++- src/SimpleElasticsearch.php | 16 ++++++++++++---- src/SimpleParseOpenGraph.php | 5 +++-- src/SimpleRequests.php | 4 +++- src/SimpleRestful.php | 4 +++- 9 files changed, 33 insertions(+), 14 deletions(-) diff --git a/helpers/ip_helper.php b/helpers/ip_helper.php index f644d37..8fb1b6e 100644 --- a/helpers/ip_helper.php +++ b/helpers/ip_helper.php @@ -246,7 +246,9 @@ function getIpInformation($ip = '') )); $response = curl_exec($curl); $err = curl_error($curl); - curl_close($curl); + if (PHP_VERSION_ID < 80000) { + curl_close($curl); + } if ($err) { $response = "cURL Error #:" . $err; } diff --git a/helpers/request_helper.php b/helpers/request_helper.php index d0d67bd..1c733a5 100644 --- a/helpers/request_helper.php +++ b/helpers/request_helper.php @@ -51,7 +51,9 @@ function sendSimpleGetRequest($url = '', $data = array(), $method = 'GET') curl_setopt_array($curl, $options); $response = curl_exec($curl); $err = curl_error($curl); - curl_close($curl); + if (PHP_VERSION_ID < 80000) { + curl_close($curl); + } if ($err) { $message = "cURL Error #: " . $err; if (function_exists('log_message')) { diff --git a/src/BaseHelper.php b/src/BaseHelper.php index 627331b..3d5a296 100644 --- a/src/BaseHelper.php +++ b/src/BaseHelper.php @@ -19,8 +19,8 @@ */ class BaseHelper { - const VERSION = '1.7.0'; - const LAST_MODIFIED = '2025-03-15'; + const VERSION = '1.7.1'; + const LAST_MODIFIED = '2026-05-17'; const PROJECT_NAME = 'CodeIgniter - Basic Helper'; const AUTHOR_NAME = 'Hung Nguyen'; const AUTHOR_FULL_NAME = 'Hung Nguyen'; diff --git a/src/BasicCurl.php b/src/BasicCurl.php index 7dd00ff..5b09ee2 100644 --- a/src/BasicCurl.php +++ b/src/BasicCurl.php @@ -700,7 +700,7 @@ public function reset() */ public function close() { - if (is_resource($this->curl)) { + if (PHP_VERSION_ID < 80000) { curl_close($this->curl); } return $this; diff --git a/src/SimpleCurl.php b/src/SimpleCurl.php index 6c1c44f..8bd859e 100644 --- a/src/SimpleCurl.php +++ b/src/SimpleCurl.php @@ -314,7 +314,9 @@ public function createCurl($url = null) public function closeCurl() { - curl_close($this->session); + if (PHP_VERSION_ID < 80000) { + curl_close($this->session); + } } public function getHttpStatus() diff --git a/src/SimpleElasticsearch.php b/src/SimpleElasticsearch.php index 4228fd8..a17f6e1 100644 --- a/src/SimpleElasticsearch.php +++ b/src/SimpleElasticsearch.php @@ -146,7 +146,9 @@ public function complexSearch( $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); } - curl_close($curl); + if (PHP_VERSION_ID < 80000) { + curl_close($curl); + } if ($fullResponse === true) { return self::fullDataResponse($response, $page, $limit, $error_msg, $httpCode); } @@ -205,7 +207,9 @@ public function filterSearch( $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); } - curl_close($curl); + if (PHP_VERSION_ID < 80000) { + curl_close($curl); + } if ($fullResponse === true) { return self::fullDataResponse($response, $page, $limit, $error_msg, $httpCode); } @@ -360,7 +364,9 @@ public function syncDataElasticsearch($data, $action, $id, $index) if (curl_errno($curl)) { $error_msg = curl_error($curl); } - curl_close($curl); + if (PHP_VERSION_ID < 80000) { + curl_close($curl); + } if (isset($error_msg)) { // echo 'error sync :' . $id . '__:' . json_encode($error_msg) . 'id :' . $index . 'action :' . $action . PHP_EOL; @@ -490,7 +496,9 @@ public static function createIndexElasticsearch($index, $listFields, $specialFie if (curl_errno($curl)) { $error_msg = curl_error($curl); } - curl_close($curl); + if (PHP_VERSION_ID < 80000) { + curl_close($curl); + } if (isset($error_msg)) { // Log::info('error sync :' . $index . '__:' . json_encode($error_msg)); diff --git a/src/SimpleParseOpenGraph.php b/src/SimpleParseOpenGraph.php index fd9f1cc..10a7a83 100644 --- a/src/SimpleParseOpenGraph.php +++ b/src/SimpleParseOpenGraph.php @@ -63,8 +63,9 @@ static public function fetch($URI) $response = curl_exec($curl); - - curl_close($curl); + if (PHP_VERSION_ID < 80000) { + curl_close($curl); + } if (!empty($response)) { return self::_parse($response); diff --git a/src/SimpleRequests.php b/src/SimpleRequests.php index 8ca2b74..efaacf5 100644 --- a/src/SimpleRequests.php +++ b/src/SimpleRequests.php @@ -214,7 +214,9 @@ public function xmlRequest($url = '', $data = '', $timeout = 60) curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $response = curl_exec($ch); - curl_close($ch); + if (PHP_VERSION_ID < 80000) { + curl_close($ch); + } if ($this->DEBUG === true) { $this->logger->info('Response from Request: ' . $response); diff --git a/src/SimpleRestful.php b/src/SimpleRestful.php index fc9c53b..09e9079 100644 --- a/src/SimpleRestful.php +++ b/src/SimpleRestful.php @@ -73,7 +73,9 @@ public static function execute($url, $type, $data = "", $header = null) $err = curl_error($curl); $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); - curl_close($curl); + if (PHP_VERSION_ID < 80000) { + curl_close($curl); + } if ($err) { echo "cURL Error #:" . $err;