diff --git a/src/Symfony/Component/HttpClient/Response/AsyncContext.php b/src/Symfony/Component/HttpClient/Response/AsyncContext.php index 1af8dbee5ede3..4e904168f1459 100644 --- a/src/Symfony/Component/HttpClient/Response/AsyncContext.php +++ b/src/Symfony/Component/HttpClient/Response/AsyncContext.php @@ -159,6 +159,14 @@ public function replaceRequest(string $method, string $url, array $options = []) $onProgress($dlNow, $dlSize, $thisInfo + $info); }; } + + if ($maxDuration = $options['max_duration'] ?? false) { + $totalElapsed = 0; + foreach ($this->info['previous_info'] as $req) { + $totalElapsed += $req['total_time']; + } + $options['timeout'] = ceil($maxDuration - $totalElapsed); + } return $this->response = $this->client->request($method, $url, ['buffer' => false] + $options); }