Skip to content

Guard curl connection sharing when CURL_LOCK_DATA_CONNECT is undefined - #230

Open
plopesc wants to merge 1 commit into
CyberSource:masterfrom
plopesc:fix/guard-curl-lock-data-connect
Open

Guard curl connection sharing when CURL_LOCK_DATA_CONNECT is undefined#230
plopesc wants to merge 1 commit into
CyberSource:masterfrom
plopesc:fix/guard-curl-lock-data-connect

Conversation

@plopesc

@plopesc plopesc commented Sep 3, 2026

Copy link
Copy Markdown

Fixes #229.

PHP only defines CURL_LOCK_DATA_CONNECT when its curl extension is built against libcurl 7.57.0 or newer. Since 0.0.72, ApiClient::__construct() uses the constant unconditionally, so on older builds (for example PHP 8.3 with libcurl 7.47 on Ubuntu 16.04, still common on managed hosting) every client instantiation throws Error: Undefined constant "CyberSource\CURL_LOCK_DATA_CONNECT".

This change keeps connection sharing exactly as it is on supported builds and skips it on builds where the constant does not exist:

  • __construct(): create the share handle only when CURL_LOCK_DATA_CONNECT is defined.
  • callApi(): attach CURLOPT_SHARE only when a share handle exists.

Verified on PHP 8.3.31 / libcurl 8.14 (share handle still created, requests unchanged) and on PHP 8.3.30 / libcurl 7.47 (no fatal, requests succeed without connection sharing).

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 CyberSource#229
@plopesc

plopesc commented Sep 3, 2026

Copy link
Copy Markdown
Author

Verified the patched client on the affected platform as promised:

  • PHP 8.3.30, libcurl 7.47.0 (Ubuntu 16.04), defined('CURL_LOCK_DATA_CONNECT') is false.
  • Before this change, new \CyberSource\ApiClient($config, $merchantConfig) threw Error: Undefined constant "CyberSource\CURL_LOCK_DATA_CONNECT" (lib/ApiClient.php:117).
  • With this change, the client constructs normally and live requests succeed: two MicroformIntegrationApi::generateCaptureContextWithHttpInfo() calls against apitest.cybersource.com (one per merchant configuration, JWT shared-secret authentication) returned valid capture contexts.
  • On PHP 8.3.31 / libcurl 8.14 the share handle is still created and requests are unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

ApiClient fatals with "Undefined constant CURL_LOCK_DATA_CONNECT" on PHP builds against libcurl < 7.57

1 participant