how to write timedout statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
infomamun
Forum Contributor
Posts: 102
Joined: Mon Dec 28, 2009 7:48 pm

how to write timedout statement

Post by infomamun »

Hi there
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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: how to write timedout statement

Post by requinix »

Keep reading the online documentation. The answer is in there.
infomamun
Forum Contributor
Posts: 102
Joined: Mon Dec 28, 2009 7:48 pm

Re: how to write timedout statement

Post by infomamun »

Address?
Post Reply