Last active
January 30, 2024 08:52
-
-
Save MikeRogers0/8492860 to your computer and use it in GitHub Desktop.
Uptime monitoring geeklet script
This file contains 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
#!/usr/bin/php | |
<?php | |
# Array of the servers you want to ping. | |
$servers = array('mikerogers.io', 'google.com', 'downserver.come'); | |
# PingDomain() from http://stackoverflow.com/a/9843251/445724 | |
function pingDomain($domain){ | |
$start_time = microtime(true); | |
$file = @fsockopen ($domain, 80, $errno, $errstr, 10); | |
$end_time = microtime(true); | |
if ($file){ # We connected ok. | |
fclose($file); | |
return floor(($end_time - $start_time) * 1000); | |
} | |
return false; | |
} | |
foreach ($servers as $server){ | |
$pingTime = pingDomain($server); | |
if($pingTime){ # it's online | |
echo "\033[0;32m".$server." (".$pingTime."ms)\033[0;254;176;19m"; | |
} else { | |
echo "\033[0;31m".$server." (Offline)\033[0;254;176;19m"; | |
} | |
echo "\n"; | |
} | |
?> |
It seems to be a php script, not a bash script. Run it as $ php uptime-monitor.php, after you change it from .sh to .php.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not getting this to work, what am I missing? Saved as .sh file, in the command line posted to the .sh file?