views:

33

answers:

2

Hi,

I'm trying to get information from a site by parsing/scraping it via PHP & Curl. But sometimes the current page doesn't finish loading, so the script runs without anything happening. It's a simple script like this...

...

curl_setopt($curl, CURLOPT_URL, $url);

$page = curl_exec($curl);

...

Is there a way to simply retry the loading of the same page if the page doesn't finish loading after (for example) 60 sec, without interrupting the complete script?

It would be great if someone could help me out with a way to realize this task.

+1  A: 

You can use CURLOPT_TIMEOUT which is the maximum number of seconds to allow cURL functions to execute.

curl_setopt($ch, CURLOPT_TIMEOUT, timeout_in_seconds);
Soufiane Hassou
thanks for the info. have you got any idea how know if there has been a timeout and repeat the process?
Mark Fischer
I think you can loop over your `curl_exec` until the return value is true. *Not tested though*
Soufiane Hassou
A: 

Something simple would be..

$bol=true;
while($bol)
{
$page = curl_exec($curl);
if($page=="")//Or whatever curl_exec returns on timeout
$bol=true;
}
stoj