Skip to content

Instantly share code, notes, and snippets.

@matsubo
Created July 17, 2012 09:05
Show Gist options
  • Save matsubo/3128217 to your computer and use it in GitHub Desktop.
Save matsubo/3128217 to your computer and use it in GitHub Desktop.
Host alive checker
<?php
/**
* Send mail with response if the target host is up
*
* @author Yuki Matsukura
* @date 2011-09-24
*/
/** @var string target URL */
$url = 'https://buy.itunes.apple.com/verifyReceipt';
// comment in for test
// $url = 'https://www.facebook.com/';
/** @var array mail address to send up notification */
$address_array = array('[email protected]');
while (true) {
print date('Y-m-d H:i:s').":";
$contents = @file_get_contents($url);
if (!$contents) {
print "error!\n";
sleep(10);
continue;
}
print "succeeded!\n";
break;
}
// notify the host is up
foreach($address_array as $address) {
mail($address, 'The host is up!', "Response:\n\n".$contents);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment