Skip to content

Comments

feat(transport): use share handle#1996

Merged
Litarnus merged 10 commits intomasterfrom
persistent-curl-handler
Feb 16, 2026
Merged

feat(transport): use share handle#1996
Litarnus merged 10 commits intomasterfrom
persistent-curl-handler

Conversation

@Litarnus
Copy link
Contributor

Adds either a regular share handle or a persistent one to our curl handle, so it can share connect, DNS and SSL between each request without having to reestablish it.

When available, it will use the persistent share handle which should improve request performance between PHP executions. It falls back to the regular share handle which can improve performance within the same PHP execution if multiple requests are performed.

@Litarnus Litarnus linked an issue Jan 13, 2026 that may be closed by this pull request
@Litarnus Litarnus marked this pull request as ready for review January 13, 2026 14:44
@Litarnus Litarnus self-assigned this Jan 13, 2026
Comment on lines 52 to 57
curl_share_setopt($this->shareHandle, \CURLOPT_SHARE, \CURL_LOCK_DATA_DNS);
if (\defined('CURL_LOCK_DATA_CONNECT')) {
curl_share_setopt($this->shareHandle, \CURLOPT_SHARE, \CURL_LOCK_DATA_CONNECT);
}
if (\defined('CURL_LOCK_DATA_SSL_SESSION')) {
curl_share_setopt($this->shareHandle, \CURLOPT_SHARE, \CURL_LOCK_DATA_SSL_SESSION);

This comment was marked as outdated.

Comment on lines 109 to 111
if ($this->shareHandle !== null) {
curl_setopt($curlHandle, \CURLOPT_SHARE, $this->shareHandle);
}

This comment was marked as outdated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation doesn't mention that curl_share_init can return false, in contrast to curl_init.

$this->sdkIdentifier = $sdkIdentifier;
$this->sdkVersion = $sdkVersion;
if (\function_exists('curl_share_init_persistent')) {
$shareOptions = [\CURL_LOCK_DATA_DNS, \CURL_LOCK_DATA_CONNECT];

This comment was marked as outdated.

// If the persistent share handle cannot be created or doesn't exist
if ($this->shareHandle === null) {
try {
$this->shareHandle = curl_share_init();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing check for false return from curl_share_init

Medium Severity

When curl_share_init() returns false (possible in PHP 7.x on failure), $this->shareHandle is set to false. The check if ($this->shareHandle !== null) passes since false !== null is true, causing curl_setopt() to be called with false as the share handle. The PR discussion explicitly noted this concern ("an extra check doesn't hurt") but the check wasn't added. This could cause warnings and prevent proper fallback behavior when share handle initialization fails.

Additional Locations (1)

Fix in Cursor Fix in Web

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

@Litarnus Litarnus merged commit 1d481fc into master Feb 16, 2026
44 checks passed
@Litarnus Litarnus deleted the persistent-curl-handler branch February 16, 2026 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider using curl_share_init_persistent if available

2 participants