//SET SOME STUFF
//Your Email
$myEmail = '';
//Your email subject for fault domains
$mySubject = '';
//File containing domains
$myDomains = '';
//Load our domains from file
$domains = file_get_contents($domainFile);
$domains = explode('\n',$domains);
//Our list of faulty domains
$issues = array();
foreach($domains as $domain){
if($resultCode = get_contents($domain) !== false){
$issues[] = array('domain'=>$domain,'code'=>$resultCode);
}
}
//Prepare the email.....
if(count($issues) == 0))
die('All Good in the hood!');
$myMessage = "I've checked a bunch of hosts, these had issues:\n";
foreach($issues as $issue){
$myMessage .="\t".$issue['domain']." - Status Code: ".$issue['code']."\n";
}
mail($myEmail,$mySubject,$myMessage);
//A neat CURL function
function get_contents($url) {
// Initiate the curl session
$ch = curl_init ();
// Set the URL
curl_setopt ( $ch, CURLOPT_URL, $url );
// Removes the headers from the output
curl_setopt ( $ch, CURLOPT_HEADER, true );
curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, TRUE );
curl_setopt ( $ch, CURLOPT_TIMEOUT, 5 );
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD');
// Execute the curl session
$output = curl_exec ( $ch );
// Close the curl session
//Get status
$info = curl_getinfo ( $ch );
$httpcode = curl_getinfo ( $ch, CURLINFO_HTTP_CODE );
curl_close ( $ch );
// Return the output as a variable
if ($httpcode !== 200) {
return $httpcode;
} else {
return false;
}
} //function