I'm using curl to request a free external 3rd party API in my PHP application. When there are too many requests at a time, it goes down and shows 504 Gateway time-out. Is there any option, when a request has no response in more than 5s then it would stop waiting for API response & go for the next statements?
As I know while adding an external API in an application, becomes a dependency. Need your attention & guidance.
What happens is that the 3rd party web server triggers “self-defense” by returning 504 error, when can’t handle certain amount of requests per minute. To avoid that you need to honor their quality of service (QoS) by throttling down the number of requests right before reaching the limit or after you get the error. You can do that by:
It’s better to avoid 504 before it happens, because the API website could return it for longer time, than the time needed to prevent it.