I'm wondering if it's possible to display a servers status on our local intranet using PHP? I want to have a little green dot displayed if the server is up and fine, an amber one if it is running slowly and a red one if it's offline. Does anyone know of any software or script that can do this?
<?php $url = 'http://example.com/'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); $status = curl_exec($ch); $time = round(curl_getinfo($ch, CURLINFO_TOTAL_TIME)); if (!$status) { $icon = 'red'; } else if ($time > 2) { $icon = 'amber'; } else { $icon = 'green'; } ?> <img src="<?php echo $icon; ?>.jpg" /> PHP:
If you're looking for something a bit more robust, rather than DIY, some people (mostly hosts, but it can be applied to different environments) like Status2k.