Adblock breaks this site

[PHP] Server Status

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

  1. syth4

    syth4 Active Member

    Joined:
    Jan 28, 2007
    Posts:
    173
    Referrals:
    1
    Sythe Gold:
    1
    [PHP] Server Status

    How do I make a server status page like Mopar does?
    Thanks :)
     
  2. cp

    cp an cat
    Banned

    Joined:
    Jan 30, 2007
    Posts:
    3,278
    Referrals:
    6
    Sythe Gold:
    0
    [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.
     
  3. syth4

    syth4 Active Member

    Joined:
    Jan 28, 2007
    Posts:
    173
    Referrals:
    1
    Sythe Gold:
    1
    [PHP] Server Status

    I mean just basic like this

    World 1 Online GoldScape.servegame.com
     
  4. Curt

    Curt Ex-Admin
    Retired Administrator Secret Asian Man PHP Programmers

    Joined:
    Apr 22, 2005
    Posts:
    2,240
    Referrals:
    5
    Sythe Gold:
    3
    Two Factor Authentication User
    [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
     
  5. syth4

    syth4 Active Member

    Joined:
    Jan 28, 2007
    Posts:
    173
    Referrals:
    1
    Sythe Gold:
    1
    [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 :)
     
  6. night

    night Member
    Banned

    Joined:
    Apr 21, 2005
    Posts:
    60
    Referrals:
    1
    Sythe Gold:
    5
    [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.
     
  7. bakatool

    bakatool Guest

    Referrals:
    0
    [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.
     
  8. cp

    cp an cat
    Banned

    Joined:
    Jan 30, 2007
    Posts:
    3,278
    Referrals:
    6
    Sythe Gold:
    0
    [PHP] Server Status

    Bakatool, don't reply to old topics.
     
  9. Game Vision

    Game Vision Guest

    Referrals:
    0
    [PHP] Server Status

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


 
 
Adblock breaks this site