Server Status Script

Discussion in 'PHP' started by aquasonic, Mar 14, 2008.

  1. #1
    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?
     
    aquasonic, Mar 14, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    <?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:
     
    nico_swd, Mar 14, 2008 IP
  3. Tyler

    Tyler Peon

    Messages:
    27
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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.
     
    Tyler, Mar 14, 2008 IP