Skip to content

Commit

Permalink
minor #37145 [HttpClient] improve monitoring of timeouts with AmpHttp…
Browse files Browse the repository at this point in the history
…Client (nicolas-grekas)

This PR was merged into the 5.1 branch.

Discussion
----------

[HttpClient] improve monitoring of timeouts with AmpHttpClient

| Q             | A
| ------------- | ---
| Branch?       | 5.1
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Replaces #36960

Commits
-------

548818d [HttpClient] improve monitoring of timeouts with AmpHttpClient
  • Loading branch information
nicolas-grekas committed Jun 9, 2020
2 parents d08db0f + 548818d commit 9e1a8f0
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/Symfony/Component/HttpClient/Response/AmpResponse.php
Expand Up @@ -173,21 +173,18 @@ private static function perform(ClientState $multi, array &$responses = null): v
*/
private static function select(ClientState $multi, float $timeout): int
{
$start = microtime(true);
$remaining = $timeout;

while (true) {
self::$delay = Loop::delay(1000 * $remaining, [Loop::class, 'stop']);
Loop::run();

if (null === self::$delay) {
return 1;
$timeout += microtime(true);
self::$delay = Loop::defer(static function () use ($timeout) {
if (0 < $timeout -= microtime(true)) {
self::$delay = Loop::delay(ceil(1000 * $timeout), [Loop::class, 'stop']);
} else {
Loop::stop();
}
});

if (0 >= $remaining = $timeout - microtime(true) + $start) {
return 0;
}
}
Loop::run();

return null === self::$delay ? 1 : 0;
}

private static function generateResponse(Request $request, AmpClientState $multi, string $id, array &$info, array &$headers, CancellationTokenSource $canceller, array &$options, \Closure $onProgress, &$handle, ?LoggerInterface $logger)
Expand Down

0 comments on commit 9e1a8f0

Please sign in to comment.