[PHP] Server Status

Discussion in 'Web Programming' started by syth4, Mar 31, 2007.

[PHP] Server Status
  1. Unread #1 - Mar 31, 2007 at 4:48 AM
  2. syth4
    Joined:
    Jan 28, 2007
    Posts:
    173
    Referrals:
    1
    Sythe Gold:
    1

    syth4 Active Member

    [PHP] Server Status

    How do I make a server status page like Mopar does?
    Thanks :)
     
  3. Unread #2 - Mar 31, 2007 at 12:21 PM
  4. cp
    Joined:
    Jan 30, 2007
    Posts:
    3,278
    Referrals:
    6
    Sythe Gold:
    0

    cp an cat
    Banned

    [PHP] Server Status

    Code:
    <?php
    phpinfo();
    ?>
    
    If you mean like, IP address, file space, etc all in an image or something, you'll have to learn the image library that comes with php.
     
  5. Unread #3 - Apr 1, 2007 at 5:01 AM
  6. syth4
    Joined:
    Jan 28, 2007
    Posts:
    173
    Referrals:
    1
    Sythe Gold:
    1

    syth4 Active Member

    [PHP] Server Status

    I mean just basic like this

    World 1 Online GoldScape.servegame.com
     
  7. Unread #4 - Apr 11, 2007 at 3:22 AM
  8. Curt
    Joined:
    Apr 22, 2005
    Posts:
    2,240
    Referrals:
    5
    Sythe Gold:
    3
    Two Factor Authentication User

    Curt Ex-Admin
    Retired Administrator Secret Asian Man PHP Programmers

    [PHP] Server Status

    PHP:
    <?php 
    /* ################################## 
    * This function will check for all ports and send an email if one is down. 
    * This will also use the Name of the Server for easy identification. 

    * This script may NOT be distributed without express written 
    * permission from Jaguar Technologies, LLC . 
    * -- www.jaguarpc.com 
    ################################### */ 

    function checkServer($server){ 

        
    //enter what email or emails (comma seperated) that should receive alerts if a server port isnt responding 
        
    $Email "person@web_site.com, another_person@web_site.com"
         
        while (list(
    $key,$port)=each($server[ports])) { 
            
    $alertEmail 0// 1=on, 0=off 

            
    $fp fsockopen($server[ip], $port, &$errno, &$errstr4); 

            
    $serviceName = array( 
                    
    "21"  =>"FTP      "
                    
    "22"  =>"SSH      "
                    
    "25"  =>"SMTP/Exim"
                    
    "53"  =>"BIND/DNS "
                    
    "80"  =>"HTTP/DNS "
                    
    "110" =>"POP3     "
                    
    "3306"=>"MySQL    "); 

            if (!
    $fp) { 
                
    $data_p "<td width=\"25\" align=\"center\"><img src=\"down.gif\"><!-- ($server[ip]:$port) --></td>"
                
    $alertEmail 1// 1=on, 0=off 
                
    $status_p "$serviceName[$port]: DOWN <---\n"
            } else { 
                
    $data_p "<td width=\"25\" align=\"center\"><img src=\"up.gif\"><!-- ($server[ip]:$port) --></td>"
                
    $status_p "$serviceName[$port]: UP\n"
                
    fclose($fp); 
            } 
            
    $data .= $data_p
            
    $status .= $status_p
        } 

        if (
    $alertEmail) { 
                
    $today date("m-d-Y H:m:s"); 
                
    $subject "Server Alert! : $server[name]"
                
    $body  "----------------------------------\n"
                
    $body .= "Server : $server[name]\n"
                
    $body .= "IP     : $server[ip]\n"
                
    $body .= "Time   : $today\n"
                
    $body .= "----------------------------------\n\n"
                
    $msg $status.$body
                
    mail($Email$subject$msg); 
        } 

        return 
    $data

    ?> 
     
    <table border="0" width="100%" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF"> 
       <tr bgcolor="#808080" style="font-weight:bold;color:#ffffff;"> 
            <td>Server Name</td> 
            <td>Info</td> 
            <td>Http</td> 
            <td>FTP</td> 
            <td>SSH</td> 
            <td>MySQL</td> 
            <td>Mail</td> 
        </tr> 
        <tr> 
            <td bgcolor="#c0c0c0">SERVERNAME</td> 
            <td align="center" bgcolor="#c0c0c0">INFO</td> 
    <?php 
    $server
    [ip] = "69.73.xxx.xxx"//server ip of the machine being monitored 
    $server[name] = "SERVERNAME"//server hostname of the machine being monitored 
    $server[ports] = array("80","21","22","3306","25"); //no need to alter these values unless you want to check different port numbers 
    echo checkServer($server); 
    ?> 
        </tr> 
    </table>
    ripped from another site. must have sockets opened
     
  9. Unread #5 - Apr 12, 2007 at 9:51 AM
  10. syth4
    Joined:
    Jan 28, 2007
    Posts:
    173
    Referrals:
    1
    Sythe Gold:
    1

    syth4 Active Member

    [PHP] Server Status

    Its not working...
    I get alot of code on the top like this...

    "FTP ", "22" =>"SSH ", "25" =>"SMTP/Exim", "53" =>"BIND/DNS ", "80" =>"HTTP/DNS ", "110" =>"POP3 ", "3306"=>"MySQL "); if (!$fp) { $data_p = ""; $alertEmail = 1; // 1=on, 0=off $status_p = "$serviceName[$port]: DOWN <---\n"; } else { $data_p = ""; $status_p = "$serviceName[$port]: UP\n"; fclose($fp); } $data .= $data_p; $status .= $status_p; } if ($alertEmail) { $today = date("m-d-Y H:m:s"); $subject = "Server Alert! : $server[name]"; $body = "----------------------------------\n"; $body .= "Server : $server[name]\n"; $body .= "IP : $server[ip]\n"; $body .= "Time : $today\n"; $body .= "----------------------------------\n\n"; $msg = $status.$body; mail($Email, $subject, $msg); } return $data; } ?>
    And it displays that...

    Help please :)
     
  11. Unread #6 - Apr 13, 2007 at 6:42 PM
  12. night
    Joined:
    Apr 21, 2005
    Posts:
    60
    Referrals:
    1
    Sythe Gold:
    5

    night Member
    Banned

    [PHP] Server Status

    that shouldnt work, what that code does is looks through the server to see if any ports are down that should be open for the server ie ftp, mysql, etc...

    You are looking for server status, if its online or not, and for that you will need a list of the server addresses.

    Code:
    <html>
    
    <head>
    </head>
    <body>
    <?
    function servstat($name, $host, $port) {
    ?>
    <tr>
    <td> <?echo($name); ?> </td>
    <td> <?echo($host); ?> </td>
    <td> <?echo($port); ?> </td>
    <?
    @$socket = fsockopen($host, $port,$errno,$errstr,5);
     if(!$socket) { 
      ?> <td> <b> <font color = "red"> Server Offline! </font> </b> </td><?
     } else { 
      fclose($socket); 
      ?> <td> <b> <font color = "green"> Server Online! </font> </b> </td><?
     } 
    ?> </tr> <?
    }
    ?> <table border = "2">
    <tr>
    <td> Name </td>
    <td> IP </td>
    <td> Port </td>
    <td> Status </td>
    </tr> <?
    servstat("halfscape", "halfscape.no-ip.org",43594);
    servstat("the baj site", "bajsite.servebeer.com",8000);
    // use the above example to enter more servers here!
    ?> </table>
    <br> Code Written by: Night </br>
    </body>
    </html>
    
    ok, there are a couple of problems with this though.... The more servers you add, the laggier it gets. Why? Becuase each time you visit this page, it gets you live status, and lags it down a lot! What you need to do is use cached data...

    You need to look up cron jobs, and enter the status of the servers into a database and then use those status as a cache. With that you can also do server uptime, etc. Its not a complicated code to do, and seems fairly easy.
     
  13. Unread #7 - Dec 16, 2007 at 6:40 PM
  14. bakatool
    Referrals:
    0

    bakatool Guest

    [PHP] Server Status

    yes but how would i do that on like a smfforfree site? cause i have part of it but i want to add servers now.
     
  15. Unread #8 - Dec 16, 2007 at 11:10 PM
  16. cp
    Joined:
    Jan 30, 2007
    Posts:
    3,278
    Referrals:
    6
    Sythe Gold:
    0

    cp an cat
    Banned

    [PHP] Server Status

    Bakatool, don't reply to old topics.
     
  17. Unread #9 - Feb 17, 2008 at 8:42 AM
  18. Game Vision
    Referrals:
    0

    Game Vision Guest

    [PHP] Server Status

< Rate my forums! | Making Whole New Forums! Where I Begin? >

Users viewing this thread
1 guest


 
 
Adblock breaks this site