Created
July 17, 2012 09:05
-
-
Save matsubo/3128217 to your computer and use it in GitHub Desktop.
Host alive checker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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