Jump to content

Display a message if website is down?


Prodigal Son

Recommended Posts

Does anyone know how I would go about doing this. I want to check if a certain website is down and if it is, I will display a message and if not display the default message.

 

So is there a function where I can do something like this:

if (website_down('http://www.example.com/')){

  echo 'Example website is down';

}

else {

  echo 'Example website is up';

}

Link to comment
https://forums.phpfreaks.com/topic/133914-display-a-message-if-website-is-down/
Share on other sites

The website_down function would need to try and contact the server and wait for an amount of time to see if the request times out - that could probably be done with a simple ping request. There isn't a function built into PHP that'll ping a server, but you might be able to use PHP's exec() function to call the server OS's ping program. Eg;

 

<?
$str=exec("ping -c 1 -w 1 ".$ip,$a,$a1);
if(strlen($str)>1){
//website's up
}else{
//website's down
}
?>

 

Completely untested of course. I started muddling together some code, then I found this so just posted the code I found on that page here. Should do what you want.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.