开发者

How to continue in case of timeout?

I am parsing some pages on the web with help of Curl and sometimes some of them are not responding. What I want to know to let the script work properly is how to set up it so that if the page is not responding Curl switches to another one by the way keeping track of how ma开发者_JS百科ny pages have not responded?


You can use the CURLOPT_CONNECTTIMEOUT and CURLOPT_TIMEOUT to set the timeouts.

Then, it's just a matter of checking the return value of curl_exec and call curl_error to get the error message if curl_exec returns false.


You should look at the curl option CURLOPT_TIMEOUT... Then all you need to do is check for the timeout in code, and if so move to the next in the list.

For an example of an open source project that does this, you can check out the PHP Mollom class, specifically the doCall method (It's just one off the top of my head that I know does this).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜