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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.