Closed
Description
Symfony version(s) affected
6.4+ (probably earlier as well)
Description
I'm experiencing strange behavior when using the pause_handler
with the CurlHttpClient
. In the case of multiple requests, the pause_handler
doesn't always work, eg:
$httpClient = new CurlHttpClient();
/** @var ResponseInterface[] $requests */
$requests = [];
for ($i = 0; $i < 100; $i++) {
$requests[] = $httpClient->request('GET', 'http://localhost:8080/ping');
}
$time = 5;
foreach ($requests as $request) {
$request->getInfo('pause_handler')($time);
$time += 5;
}
foreach ($requests as $request) {
$output->writeln($request->getContent());
}
2024-01-24T02:30:54.847983
2024-01-24T02:30:46.548562
2024-01-24T02:30:46.467222
2024-01-24T02:30:46.439153
2024-01-24T02:30:46.494591
2024-01-24T02:30:46.521667
2024-01-24T02:30:46.392766
2024-01-24T02:30:46.574905
2024-01-24T02:30:55.835802
2024-01-24T02:30:47.606177
2024-01-24T02:30:47.578046
2024-01-24T02:30:47.547933
However, if I set the pause_handler
earlier, everything works as expected:
$httpClient = new CurlHttpClient();
/** @var ResponseInterface[] $requests */
$requests = [];
$time = 5;
for ($i = 0; $i < 100; $i++) {
$requests[] = $request = $httpClient->request('GET', 'http://localhost:8080/ping');
$request->getInfo('pause_handler')($time);
$time += 5;
}
foreach ($requests as $request) {
$output->writeln($request->getContent());
}
2024-01-24T02:33:30.222284
2024-01-24T02:33:35.223621
2024-01-24T02:33:40.223094
2024-01-24T02:33:45.218890
2024-01-24T02:33:50.208427
2024-01-24T02:33:55.208496
2024-01-24T02:34:00.207538
2024-01-24T02:34:05.221313
2024-01-24T02:34:10.209738
2024-01-24T02:34:15.210125
2024-01-24T02:34:20.211701
2024-01-24T02:34:25.207769
The problem seems to be caused by the following code:
symfony/src/Symfony/Component/HttpClient/Response/CurlResponse.php
Lines 100 to 103 in 0294563
I'm not really sure what this code is meant to do or if this is expected behavior.
It should be noted that the NativeHttpClient
always works as expected.
How to reproduce
I've create an example application: example.zip
composer install
symfony serve --port 8080 (or php -S localhost:8080 public/)
bin/console app:ping-not-ok
bin/console app:ping-ok
Possible Solution
No response
Additional Context
No response