From eeb7ddefa191c4e8d8488511faa030ca895dcd9a Mon Sep 17 00:00:00 2001 From: Martin Linzmayer Date: Tue, 13 Jan 2026 14:36:13 +0100 Subject: [PATCH 1/3] feat(transport): use share handle --- src/HttpClient/HttpClient.php | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/HttpClient/HttpClient.php b/src/HttpClient/HttpClient.php index 2a373d930..33d4d5d07 100644 --- a/src/HttpClient/HttpClient.php +++ b/src/HttpClient/HttpClient.php @@ -22,10 +22,44 @@ class HttpClient implements HttpClientInterface */ protected $sdkVersion; + /** + * Either a persistent share handle or a regular share handle, or null if no share handle can be obtained. + * + * @var object|resource|null + */ + private $shareHandle; + public function __construct(string $sdkIdentifier, string $sdkVersion) { $this->sdkIdentifier = $sdkIdentifier; $this->sdkVersion = $sdkVersion; + if (\function_exists('curl_share_init_persistent')) { + $shareOptions = [\CURL_LOCK_DATA_DNS, \CURL_LOCK_DATA_CONNECT]; + if (\defined('CURL_LOCK_DATA_SSL_SESSION')) { + $shareOptions[] = \CURL_LOCK_DATA_SSL_SESSION; + } + try { + $this->shareHandle = curl_share_init_persistent($shareOptions); + } catch (\Throwable $throwable) { + // don't crash if the share handle cannot be created + } + } + + // If the persistent share handle cannot be created or doesn't exist + if ($this->shareHandle === null) { + try { + $this->shareHandle = curl_share_init(); + 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); + } + } catch (\Throwable $throwable) { + // don't crash if the share handle cannot be created + } + } } public function sendRequest(Request $request, Options $options): Response @@ -72,6 +106,9 @@ public function sendRequest(Request $request, Options $options): Response curl_setopt($curlHandle, \CURLOPT_RETURNTRANSFER, true); curl_setopt($curlHandle, \CURLOPT_HEADERFUNCTION, $responseHeaderCallback); curl_setopt($curlHandle, \CURLOPT_HTTP_VERSION, \CURL_HTTP_VERSION_1_1); + if ($this->shareHandle !== null) { + curl_setopt($curlHandle, \CURLOPT_SHARE, $this->shareHandle); + } $httpSslVerifyPeer = $options->getHttpSslVerifyPeer(); if (!$httpSslVerifyPeer) { From c563cef79b64269d1232f685ca1884d53c8b1c36 Mon Sep 17 00:00:00 2001 From: Martin Linzmayer Date: Tue, 13 Jan 2026 15:48:21 +0100 Subject: [PATCH 2/3] use proper option --- src/HttpClient/HttpClient.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/HttpClient/HttpClient.php b/src/HttpClient/HttpClient.php index 33d4d5d07..89bfa3ce4 100644 --- a/src/HttpClient/HttpClient.php +++ b/src/HttpClient/HttpClient.php @@ -49,12 +49,12 @@ public function __construct(string $sdkIdentifier, string $sdkVersion) if ($this->shareHandle === null) { try { $this->shareHandle = curl_share_init(); - curl_share_setopt($this->shareHandle, \CURLOPT_SHARE, \CURL_LOCK_DATA_DNS); + curl_share_setopt($this->shareHandle, \CURLSHOPT_SHARE, \CURL_LOCK_DATA_DNS); if (\defined('CURL_LOCK_DATA_CONNECT')) { - curl_share_setopt($this->shareHandle, \CURLOPT_SHARE, \CURL_LOCK_DATA_CONNECT); + curl_share_setopt($this->shareHandle, \CURLSHOPT_SHARE, \CURL_LOCK_DATA_CONNECT); } if (\defined('CURL_LOCK_DATA_SSL_SESSION')) { - curl_share_setopt($this->shareHandle, \CURLOPT_SHARE, \CURL_LOCK_DATA_SSL_SESSION); + curl_share_setopt($this->shareHandle, \CURLSHOPT_SHARE, \CURL_LOCK_DATA_SSL_SESSION); } } catch (\Throwable $throwable) { // don't crash if the share handle cannot be created From 224bd159242aeb7c6bb35301e1cd009ae437d76a Mon Sep 17 00:00:00 2001 From: Martin Linzmayer Date: Tue, 13 Jan 2026 16:02:14 +0100 Subject: [PATCH 3/3] add guard for constant --- src/HttpClient/HttpClient.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/HttpClient/HttpClient.php b/src/HttpClient/HttpClient.php index 89bfa3ce4..10754eff4 100644 --- a/src/HttpClient/HttpClient.php +++ b/src/HttpClient/HttpClient.php @@ -34,7 +34,10 @@ public function __construct(string $sdkIdentifier, string $sdkVersion) $this->sdkIdentifier = $sdkIdentifier; $this->sdkVersion = $sdkVersion; if (\function_exists('curl_share_init_persistent')) { - $shareOptions = [\CURL_LOCK_DATA_DNS, \CURL_LOCK_DATA_CONNECT]; + $shareOptions = [\CURL_LOCK_DATA_DNS]; + if (\defined('CURL_LOCK_DATA_CONNECT')) { + $shareOptions[] = \CURL_LOCK_DATA_CONNECT; + } if (\defined('CURL_LOCK_DATA_SSL_SESSION')) { $shareOptions[] = \CURL_LOCK_DATA_SSL_SESSION; }