From fb1cfe5d058d3ccc0622b6ecc90e46e340c6cf3c Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 2 Dec 2025 09:43:20 +0100 Subject: [PATCH 1/5] Share DNS and Connect between curl requests reduces overhead when doing multiple curl requests per php-request. other places which manually invoke `curl_init` can benefit in a similar way by adding such code. `curl_multi_*` will automatically share caches between requests, without the need for additional code. --- src/JiraClient.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/JiraClient.php b/src/JiraClient.php index 86b4db7d..657a8e28 100644 --- a/src/JiraClient.php +++ b/src/JiraClient.php @@ -160,6 +160,18 @@ public function curlPrepare(\CurlHandle|bool $ch, array $curl_http_headers, ?str curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->getConfiguration()->getTimeout()); } + if (\function_exists('curl_share_init_persistent')) { + $share = curl_share_init_persistent([ + CURL_LOCK_DATA_DNS, + CURL_LOCK_DATA_CONNECT, + ]); + } else { + $share = curl_share_init(); + curl_share_setopt($share, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS); + curl_share_setopt($share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT); + } + curl_setopt($ch, CURLOPT_SHARE, $share); + return $curl_http_headers; } From 6e912fce1e1fbb0775dd3c820e767203ab0a6b79 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 4 Dec 2025 07:23:10 +0100 Subject: [PATCH 2/5] fix --- src/JiraClient.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/JiraClient.php b/src/JiraClient.php index 657a8e28..a3d879c3 100644 --- a/src/JiraClient.php +++ b/src/JiraClient.php @@ -35,6 +35,8 @@ class JiraClient */ protected \CurlHandle $curl; + protected \CurlShareHandle $curlShare = null; + /** * Monolog instance. */ @@ -160,17 +162,19 @@ public function curlPrepare(\CurlHandle|bool $ch, array $curl_http_headers, ?str curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->getConfiguration()->getTimeout()); } - if (\function_exists('curl_share_init_persistent')) { - $share = curl_share_init_persistent([ - CURL_LOCK_DATA_DNS, - CURL_LOCK_DATA_CONNECT, - ]); - } else { - $share = curl_share_init(); - curl_share_setopt($share, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS); - curl_share_setopt($share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT); + if ($this->curlShare === null) { + if (\function_exists('curl_share_init_persistent')) { + $this->curlShare = curl_share_init_persistent([ + CURL_LOCK_DATA_DNS, + CURL_LOCK_DATA_CONNECT, + ]); + } else { + $this->curlShare = curl_share_init(); + curl_share_setopt($share, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS); + curl_share_setopt($share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT); + } } - curl_setopt($ch, CURLOPT_SHARE, $share); + curl_setopt($ch, CURLOPT_SHARE, $this->curlShare); return $curl_http_headers; } From 8d06bb2684963073dc6f6d31a1c2d2fa9d265a2c Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 4 Dec 2025 07:27:22 +0100 Subject: [PATCH 3/5] cs --- src/JiraClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JiraClient.php b/src/JiraClient.php index a3d879c3..8439a0af 100644 --- a/src/JiraClient.php +++ b/src/JiraClient.php @@ -34,7 +34,7 @@ class JiraClient * CURL instance. */ protected \CurlHandle $curl; - + protected \CurlShareHandle $curlShare = null; /** From af44c38a39484ae073b8f9fd33639cb5e7197cd5 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 4 Dec 2025 07:32:38 +0100 Subject: [PATCH 4/5] cs --- src/JiraClient.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/JiraClient.php b/src/JiraClient.php index 8439a0af..6a2c5335 100644 --- a/src/JiraClient.php +++ b/src/JiraClient.php @@ -34,9 +34,12 @@ class JiraClient * CURL instance. */ protected \CurlHandle $curl; - + + /** + * CURL share instance. + */ protected \CurlShareHandle $curlShare = null; - + /** * Monolog instance. */ From 2239a2e0119f94278dbdf6896a5b55ff1d4b950b Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 4 Dec 2025 07:39:15 +0100 Subject: [PATCH 5/5] fix type --- src/JiraClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JiraClient.php b/src/JiraClient.php index 6a2c5335..5ee589e1 100644 --- a/src/JiraClient.php +++ b/src/JiraClient.php @@ -38,7 +38,7 @@ class JiraClient /** * CURL share instance. */ - protected \CurlShareHandle $curlShare = null; + protected \CurlShareHandle|\CurlSharePersistentHandle|null $curlShare = null; /** * Monolog instance.