I am using curl to output a remote server's page as below:
Code: Select all
function output_curl($url)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 15);
$html = curl_exec($curl); // execute the curl command
curl_close($curl); // close the connection
return $html; // and finally, return $html
}
$url = 'http://forums.devnetwork.net/';
$data = output_curl($url);Please note that a 15 seconds time out has been settled in the code. Suppose, somehow the timout period was over and the curl couldnot completed the execution. Then after timeout period I want to show a message like this:
Code: Select all
if($data=timedout){
echo "Sorry! Server is down, Page cannot be displayed. Please reload the page";
}else{
//do something else with the output
}my question is how I can write the timedout statement? I think ($data=timedout) is not the correct syntax. What should be in place of "timedout" to point out an time out error?
Regards