phool4fool
203.***.***.***Server Status Script
This simple PHP script will attempt to connect to port 80 on a server and if port 80 is unresponsive the script will send out an e-mail to a specified e-mail address.PHP Example:
PHP code:
//Websites to check the status of. You can list as many as you want. If you want to check the status of only one site remove the others.
$sites = array();
$sites[] = 'cnn.com';
$sites[] = 'example.com';
$fails = array();
foreach($sites as $site)
{
$sock = fsockopen($site, 80, $errno, $errstr, 5);
if (!$sock)
{
$fails[] = $site;
}
}
if(count($fails) > 0)
{
// The e-mail address you want the report of a unresponsive server sent to. Example: 4251234567@tmomail.net.
// You can send the report to multiple addresses, i.e.: 4251234567@tmomail.net,7035551234@messaging.nextel.com.
$to = "4251234567@tmomail.net";
//This code sends out the e-mail.
$subject = "Server Status: " . count($fails) . " sites down";
$message = "The following " . count($fails) . " sites failed to respond on " . date("r") . ":\r\n\r\n";
foreach($fails as $failed)
{
$message .= $failed . "\r\n";
}
mail($to, $subject, $message);
}