Erik Kalkoken Erik Kalkoken - 3 months ago 52x
PHP Question

On which errors should curl retry for web API requests?

I am implementing a class which retrieves information from a web API. It returns XML to HTTPS GET requests. I am using curl for the request and want it to retry in case of errors to make it more robust.

I am currently retrying (up to 3 times) for all curl errors and HTTP error 500, but I am wondering if that is the best approach.

So on which curl and http errors should I retry for my API requests? what is best practice?


I'd would say don't retry on 500 errors. That's some error on the API side and that's unlikely to change (at least, in a few seconds).

If you really want to retry on some responses, do it on timeouts, ie. 408, 504. It can be that the server is receiving more requests than it can handle, and waiting a few seconds to try again may be worthy.