简体   繁体   中英

Whats the best way to handle failed web requests?

I have web requests that fail every now and then, however my application really needs the data that service provides.

What is the best pattern for retying the request?

I know there would be issues with cascading if I just kept trying indefinitely and straight away.

I am using the cURL library in PHP

Google uses an algorithm that tries after 2^retrycount seconds. I think that is a good algorithm, but if you need the information right now, try to cache the answer and use the cache until the resource is available again. If it's possible to wait that long, I'd recommend the Google algorithm.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM