tags:

views:

36

answers:

2

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 many pages have not responded?

+1  A: 

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.

Artefacto
A: 

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).

ircmaxell