Summary
Since 0.0.72, ApiClient::__construct() unconditionally runs:
if (self::$shareHandle === null) {
self::$shareHandle = curl_share_init();
curl_share_setopt(self::$shareHandle, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT);
}
PHP only defines CURL_LOCK_DATA_CONNECT when the curl extension was compiled against libcurl 7.57.0 or newer. On older builds (for example PHP 8.3.30 on Ubuntu 16.04 with libcurl 7.47.0, still common on managed hosting) every client instantiation throws:
Error: Undefined constant "CyberSource\CURL_LOCK_DATA_CONNECT" in CyberSource\ApiClient->__construct() (lib/ApiClient.php:117)
This makes the SDK unusable on those platforms, and it is a hard failure rather than a degraded one, even though connection sharing is only an optimization. The same code is still present on master and in 0.0.73–0.0.75.
Steps to reproduce
- Use PHP whose
curl_version()['version'] is below 7.57.0 (php -r 'var_dump(defined("CURL_LOCK_DATA_CONNECT"));' prints false).
- Install
cybersource/rest-client-php 0.0.72 or later.
new \CyberSource\ApiClient($config, $merchantConfig);
Proposed fix
Guard the share handle on the constant and only attach it when it exists:
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);
}
and in callApi():
if (self::$shareHandle !== null) {
curl_setopt($curl, CURLOPT_SHARE, self::$shareHandle);
}
Newer builds keep connection sharing; older builds fall back to one connection per request instead of failing. Happy to open a PR with this change.
Summary
Since 0.0.72,
ApiClient::__construct()unconditionally runs:PHP only defines
CURL_LOCK_DATA_CONNECTwhen the curl extension was compiled against libcurl 7.57.0 or newer. On older builds (for example PHP 8.3.30 on Ubuntu 16.04 with libcurl 7.47.0, still common on managed hosting) every client instantiation throws:This makes the SDK unusable on those platforms, and it is a hard failure rather than a degraded one, even though connection sharing is only an optimization. The same code is still present on
masterand in 0.0.73–0.0.75.Steps to reproduce
curl_version()['version']is below 7.57.0 (php -r 'var_dump(defined("CURL_LOCK_DATA_CONNECT"));'printsfalse).cybersource/rest-client-php0.0.72 or later.new \CyberSource\ApiClient($config, $merchantConfig);Proposed fix
Guard the share handle on the constant and only attach it when it exists:
and in
callApi():Newer builds keep connection sharing; older builds fall back to one connection per request instead of failing. Happy to open a PR with this change.