tags:

views:

26

answers:

1

Using PHP's Curl how do I know that the page is not responding so as to grab another one?

+2  A: 

Use the CURLOPT_CONNECTTIMEOUT option:

// Wait two seconds before bailing
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);

There's also CURLOPT_TIMEOUT, which works for an entire request call (including DNS fetching and reading the data).

To check if a call did time out, you may be able to check its return value. If not, the CURL handler's curl_errno is set, which you can compare to CURLE_OPERATION_TIMEDOUT (or just CURLE_OK).

strager
But this is not his question, is it? The question is how to tell a call timed out (as opposed to some other error)
Pekka
@Pekka, Oh, seems I misread the question. I'll update my answer.
strager