ApiClient fatals with "Undefined constant CURL_LOCK_DATA_CONNECT" on PHP builds against libcurl < 7.57
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 88/100
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.
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.
- Dominant language
- PHP
- Stars
- 41
- Forks
- 77
- Avg merge
- 26m
- Merged PRs (30d)
- 1
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.
More from CyberSource/cybersource-rest-client-php
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 3/5 1-2 days Newbie friendliness 64/100
CyberSource/cybersource-rest-client-php#228 · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
-
Difficulty 3/5 1-2 days Newbie friendliness 64/100
All issues in CyberSource/cybersource-rest-client-php
Similar issues
-
priority: p3
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
googleapis/librarian#7636 ·
-
0. Needs triage bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
nextcloud/fulltextsearch#1011 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
phpstan/phpstan-doctrine#794 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Automattic/static-site-importer#1767 ·