Skip to content

Commit 617c98e

Browse files
[HttpClient] Fix global state preventing two CurlHttpClient instances from working together
1 parent 279f53a commit 617c98e

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
@@ -36,6 +36,7 @@ final class CurlClientState extends ClientState
3636
public $execCounter = \PHP_INT_MIN;
3737
/** @var LoggerInterface|null */
3838
public $logger;
39+
public $performing = false;
3940

4041
public static $curlVersion;
4142

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 $performing = false;
3635
private $multi;
3736
private $debugBuffer;
3837

@@ -179,7 +178,7 @@ public function __construct(CurlClientState $multi, $ch, array $options = null,
179178
unset($multi->pauseExpiries[$id], $multi->openHandles[$id], $multi->handlesActivity[$id]);
180179
curl_setopt($ch, \CURLOPT_PRIVATE, '_0');
181180

182-
if (self::$performing) {
181+
if ($multi->performing) {
183182
return;
184183
}
185184

@@ -237,13 +236,13 @@ public function getInfo(string $type = null)
237236
*/
238237
public function getContent(bool $throw = true): string
239238
{
240-
$performing = self::$performing;
241-
self::$performing = $performing || '_0' === curl_getinfo($this->handle, \CURLINFO_PRIVATE);
239+
$performing = $this->multi->performing;
240+
$this->multi->performing = $performing || '_0' === curl_getinfo($this->handle, \CURLINFO_PRIVATE);
242241

243242
try {
244243
return $this->doGetContent($throw);
245244
} finally {
246-
self::$performing = $performing;
245+
$this->multi->performing = $performing;
247246
}
248247
}
249248

@@ -287,7 +286,7 @@ private static function schedule(self $response, array &$runningResponses): void
287286
*/
288287
private static function perform(ClientState $multi, array &$responses = null): void
289288
{
290-
if (self::$performing) {
289+
if ($multi->performing) {
291290
if ($responses) {
292291
$response = current($responses);
293292
$multi->handlesActivity[(int) $response->handle][] = null;
@@ -298,7 +297,7 @@ private static function perform(ClientState $multi, array &$responses = null): v
298297
}
299298

300299
try {
301-
self::$performing = true;
300+
$multi->performing = true;
302301
++$multi->execCounter;
303302
$active = 0;
304303
while (\CURLM_CALL_MULTI_PERFORM === ($err = curl_multi_exec($multi->handle, $active))) {
@@ -335,7 +334,7 @@ private static function perform(ClientState $multi, array &$responses = null): v
335334
$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)));
336335
}
337336
} finally {
338-
self::$performing = false;
337+
$multi->performing = false;
339338
}
340339
}
341340

0 commit comments

Comments
 (0)