简体   繁体   English

处理失败的Web请求的最佳方法是什么?

[英]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. 我的Web请求有时会失败,但是我的应用程序确实需要服务提供的数据。

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 我在PHP中使用cURL库

Google uses an algorithm that tries after 2^retrycount seconds. Google使用的算法会在2 ^ retrycount秒后尝试。 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. 如果可以等待那么长时间,我建议使用Google算法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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