From 0da489125f5aa32cab028baded809c7eb65c63ba Mon Sep 17 00:00:00 2001 From: Pablo Lopez // plopesc Date: Thu, 3 Sep 2026 12:41:24 +0200 Subject: [PATCH] Guard curl connection sharing when CURL_LOCK_DATA_CONNECT is undefined PHP only defines CURL_LOCK_DATA_CONNECT when its curl extension is built against libcurl 7.57.0 or newer. On older builds every ApiClient construction fataled with an undefined constant since 0.0.72. Skip the share handle when the constant is missing so those platforms fall back to one connection per request instead of failing. Fixes #229 --- lib/ApiClient.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/ApiClient.php b/lib/ApiClient.php index a7af0ea1..07c0700f 100755 --- a/lib/ApiClient.php +++ b/lib/ApiClient.php @@ -112,7 +112,10 @@ public function __construct(\CyberSource\Configuration $config = null, \CyberSou echo "Merchant Configuration cannot be null."; } - if (self::$shareHandle === null) { + // Connection sharing needs PHP built against libcurl >= 7.57.0, where + // CURL_LOCK_DATA_CONNECT exists. Older builds simply skip the share + // handle instead of failing with an undefined constant. + if (self::$shareHandle === null && defined('CURL_LOCK_DATA_CONNECT')) { self::$shareHandle = curl_share_init(); curl_share_setopt(self::$shareHandle, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT); } @@ -318,7 +321,9 @@ public function callApi($resourcePath, $method, $queryParams, $postData, $header $curl = curl_init(); - curl_setopt($curl, CURLOPT_SHARE, self::$shareHandle); + if (self::$shareHandle !== null) { + curl_setopt($curl, CURLOPT_SHARE, self::$shareHandle); + } // set timeout, if needed if ($this->config->getCurlTimeout() !== 0) { curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout());