In the new Symfomy 5.2 a Retryable HttpClient was implemented.
Failed requests can now be retried by default in case of failure.
However, I could not debug or understand how the timeout
option is parsed in it.
For example:
$response = $client->request('POST', $url, [
'body' => $reqBody,
'timeout' => 45
]);
If the first request fails after 30 seconds, and the second attempt succeed after another 30 seconds, do I get a timeout error (considering both requests took 30 seconds, 30+30 = 60s)?
Or the timeout option for this case will be valid for every attempt?
If so, is there a way to set the global timeout of the request?
After some testing using webhook.site with some timeout options, I could see the
timeout
option refers to every request.I could not find a way to set the total timeout, but at least I was able to avoid further retries if an specific time had elapsed.
For that, I created a custom strategy. I added the following to my framework.yaml file:
And under src/MyStrategy.php I did:
But the original problem still remains. If the first attempt fails in 30 seconds, a new one can still take up to 40 seconds to be completed, and the whole thing can take up to 70 seconds, instead of 40.