The source of server_mon.php (click to demo the file) viewed 8389 times.
If I wrote this code, then it is licensed under the GPL. If someone else wrote it, then please ask them if you want to use the code.
<?php
/////////////////////////////////////////////////////
// Server Monitor v1.0 - sebflipper Copyright 2004 //
// http://www.sebflipper.com/ //
// //
// This is a simple script to monitor a //
// list of ports from a list of domains //
//
// Don't forget to download green.gif and //
// red.gif for the status icons //
/////////////////////////////////////////////////////
// Config Area
// Enter a list of domain names you want to monitor
$domains = array("sebflipper.com", "multi-forums.net", "woollydogpaintings.com", "pdjkeelan.co.uk", "ffhut.co.uk");
// Enter a list of ports you wish to monitor (80 = HTTP, 21 = FTP, 25 = SMTP, 3306 = MySQL)
$ports = array("80", "21", "25", "3306");
// How often the page should refresh
$page_refresh = "300"; // in seconds
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="REFRESH" content="<?php echo $page_refresh; ?>">
<title>Server Monitor</title>
<style type="text/css">
<!--
body {
font-family: Arial, Helvetica, sans-serif;
font-size: small;
}
-->
</style>
</head>
</body>
<?php
// PHP Script
// Turn off all error reporting
// Removes errors like fsockopen failed if the script couldn't connect to the port
error_reporting(0);
// Main moniting function
function server_monitor($domain,$port) {
$fp = fsockopen ($domain, $port, $errno, $errstr, 10);
if (!$fp) {
return "<img src=red.gif alt='Status: Down, Domain: $domain, Port: $port'>\n";
} else {
return "<img src=green.gif alt='Status: Up, Domain: $domain, Port: $port'>\n";
}
fclose($fp);
}
// Foreach array
foreach ($domains as $domain_value) {
echo "<b>Checking $domain_value...</b><br>\n";
echo "<table border=1 cellpadding=0 cellspacing=0 bordercolor=#000000><tr>\n";
foreach ($ports as $port_value) {
echo "<td>Port: $port_value</td>";
}
echo "</tr>\n<tr>\n";
foreach ($ports as $port_value) {
echo "<td><center>". server_monitor($domain_value,$port_value) . "</center></td>\n";
}
echo "</tr></table><br><br>\n";
}
?>
Don't forget to download <img src=green.gif> and <img src=red.gif> and place them in the same folder as this script
</body>
</html>
If you want to have a look at the source code, chose a file from this list:
To colour code your own PHP paste it here: