CyberSource / CyberSource/cybersource-rest-client-php
ApiClient fatals with "Undefined constant CURL_LOCK_DATA_CONNECT" on PHP builds against libcurl < 7.57
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 41
- Forks
- 77
- Avg merge
- 26m
- Merged PRs (30d)
- 1
Description
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"));'printsfalse). - Install
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:
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in lib/ApiClient.php, reading the __construct() share-handle setup and the callApi() path that applies CURLOPT_SHARE. Reproduce the failure with defined('CURL_LOCK_DATA_CONNECT') on an older libcurl build, then verify that newer builds retain connection sharing while older builds can instantiate and make requests without the constant error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100