Skip to content

Commit 3f5545a

Browse files
Merge branch '5.4' into 6.2
* 5.4: [HttpClient] Fix global state preventing two CurlHttpClient instances from working together
2 parents 7a3fda8 + 617c98e commit 3f5545a

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

Internal/CurlClientState.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ final class CurlClientState extends ClientState
2525
{
2626
public ?\CurlMultiHandle $handle;
2727
public ?\CurlShareHandle $share;
28+
public bool $performing = false;
2829

2930
/** @var PushedResponse[] */
3031
public array $pushedResponses = [];

Response/CurlResponse.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ final class CurlResponse implements ResponseInterface, StreamableInterface
3232
}
3333
use TransportResponseTrait;
3434

35-
private static bool $performing = false;
3635
private CurlClientState $multi;
3736

3837
/**
@@ -182,7 +181,7 @@ public function __construct(CurlClientState $multi, \CurlHandle|string $ch, arra
182181
unset($multi->pauseExpiries[$id], $multi->openHandles[$id], $multi->handlesActivity[$id]);
183182
curl_setopt($ch, \CURLOPT_PRIVATE, '_0');
184183

185-
if (self::$performing) {
184+
if ($multi->performing) {
186185
return;
187186
}
188187

@@ -234,13 +233,13 @@ public function getInfo(string $type = null): mixed
234233

235234
public function getContent(bool $throw = true): string
236235
{
237-
$performing = self::$performing;
238-
self::$performing = $performing || '_0' === curl_getinfo($this->handle, \CURLINFO_PRIVATE);
236+
$performing = $this->multi->performing;
237+
$this->multi->performing = $performing || '_0' === curl_getinfo($this->handle, \CURLINFO_PRIVATE);
239238

240239
try {
241240
return $this->doGetContent($throw);
242241
} finally {
243-
self::$performing = $performing;
242+
$this->multi->performing = $performing;
244243
}
245244
}
246245

@@ -279,7 +278,7 @@ private static function schedule(self $response, array &$runningResponses): void
279278
*/
280279
private static function perform(ClientState $multi, array &$responses = null): void
281280
{
282-
if (self::$performing) {
281+
if ($multi->performing) {
283282
if ($responses) {
284283
$response = current($responses);
285284
$multi->handlesActivity[(int) $response->handle][] = null;
@@ -290,7 +289,7 @@ private static function perform(ClientState $multi, array &$responses = null): v
290289
}
291290

292291
try {
293-
self::$performing = true;
292+
$multi->performing = true;
294293
++$multi->execCounter;
295294
$active = 0;
296295
while (\CURLM_CALL_MULTI_PERFORM === ($err = curl_multi_exec($multi->handle, $active))) {
@@ -327,7 +326,7 @@ private static function perform(ClientState $multi, array &$responses = null): v
327326
$multi->handlesActivity[$id][] = \in_array($result, [\CURLE_OK, \CURLE_TOO_MANY_REDIRECTS], true) || '_0' === $waitFor || curl_getinfo($ch, \CURLINFO_SIZE_DOWNLOAD) === curl_getinfo($ch, \CURLINFO_CONTENT_LENGTH_DOWNLOAD) ? null : new TransportException(ucfirst(curl_error($ch) ?: curl_strerror($result)).sprintf(' for "%s".', curl_getinfo($ch, \CURLINFO_EFFECTIVE_URL)));
328327
}
329328
} finally {
330-
self::$performing = false;
329+
$multi->performing = false;
331330
}
332331
}
333332

0 commit comments

Comments
 (0)