Last active
March 4, 2021 22:41
-
-
Save geerlingguy/4675221 to your computer and use it in GitHub Desktop.
Simple script to use the Ping PHP library and print a list of servers and their statuses. Written for a school that needs to track whether some local Apple TVs are active.
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
<?php | |
/** | |
* @file | |
* Show the status of various Apple TVs. | |
*/ | |
// Place Ping.php in the same folder as this script. | |
require_once('Ping.php'); | |
use JJG\Ping as Ping; | |
// Define a list of servers to check. Each item in the array is one server; the | |
// key is the title of the server, and the value is the ip address or host name | |
// that will be checked. | |
$servers_to_check = array( | |
'Google' => 'www.google.com', | |
'Apple' => 'www.apple.com', | |
'Yahoo' => 'www.yahoo.com', | |
'Apple TV - Room 201' => '192.168.1.123', // Define as many as you'd like. | |
); | |
// Print a tite for the page. | |
print '<h1 class="title">' . 'Server Status Page' . '</h1>'; | |
// Begin an unordered list. | |
print '<ul class="server-list">' . "\r\n"; | |
// Loop through the servers defined above, and print the status of each. | |
foreach ($servers_to_check as $name => $address) { | |
// Begin the list definition. | |
print '<li class="server"><span class="server-name">' . $name . '</span>'; | |
// Ping the server, and print an up or down status. You can use CSS to hide | |
// the 'Up' or 'Down' text and replace it with a graphic like a red or green | |
// status indicator. | |
$ping = new Ping($address); | |
$latency = $ping->ping(); | |
if ($latency) { | |
print '<span class="status up">Up</span>'; | |
} | |
else { | |
print '<span class="status down">Down</span>'; | |
} | |
// End the list item definition. | |
print '</li>'; | |
} | |
// End the unordered list. | |
print '</ul>'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Been using curl to check for server uptime, then was getting 0 code. I found this code useful.