FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Checking server status (ports) using PHP





Marston
Could someone show me a simple way to check ports on a server (in this case, frihost server 2)? I just want a simple way to display whether or not HTTP, FTP, POP3, WebMail, and MySQL are up. I've seen it in a few signatures around here, but I just can't seem to find any tutorial on how to accomplish this. Any help is appreciated. Thanks in advance. Smile
wumingsden
Marston wrote:
Could someone show me a simple way to check ports on a server (in this case, frihost server 2)? I just want a simple way to display whether or not HTTP, FTP, POP3, WebMail, and MySQL are up. I've seen it in a few signatures around here, but I just can't seem to find any tutorial on how to accomplish this. Any help is appreciated. Thanks in advance. Smile



filename: server2.php

Code:
<?php
//based on some script I saw on the net
//status pics
$live = "live2.gif";
$dead = "dead2.gif";

//The status checking script
$link = $_GET['link'].":";
$s_link = str_replace("::", ":", $link);
list($addr,$port)= explode (':',"$s_link");
if (empty($port)){
   $port = 80;
}
//Test connection
$churl = @fsockopen(server($addr), $port, $errno, $errstr, 20);
             if (!$churl){
          //echo $errstr;
                header("Location: $dead");
                }
             else {
                  header("Location: $live");             
        }
function server($addr){
         if(strstr($addr,"/")){$addr = substr($addr, 0, strpos($addr, "/"));}
         return $addr;
}
?>


then something like this to display the link (my index.php)...

Code:
<tr>
    <td><font size="2" color="#FFFFFF">FriHost Server 2 HTTP</font></td>
    <td><img src="server2.php?link=216.32.85.170:80" ></td>
  </tr>
  <tr>
    <td><font size="2" color="#FFFFFF">FriHost Server 2 FTP</font></td>
    <td><img src="server2.php?link=216.32.85.170:21" ></td>
  </tr>
  <tr>
    <td><font size="2" color="#FFFFFF">FriHost Server 2 mySQL</font></td>
    <td><img src="server2.php?link=216.32.85.170:3306" ></td>
  </tr>


feel free to use my images which are at www.mezmorizing.net/status/dead2.gif and www.mezmorizing.net/status/live2.gif

Note: there is a slight problem with the script. It will only show information about the server on which it is located, therefore there is no need to put in a complete different IP because it will not work. This means that you cannot see when the server is completely down because when it is the script won't be accessable.
Marston
Thanks Smile.
Related topics
[tutor] How to protect images without htaccess using PHP
Checking Server Status, Ping a Server (lots of purposes)
Using PHP
Includ Images using PHP.
How to start using PHP? Help!
Server status script
Frihost server status checker
Website Designing using PHP
I am trying to build a contact form using php and flash
Checking if ports are up using PHP
Hot to change "Reset Ownership" using php?
Access Java 1.6 Web service using php client
Server Status Page? Coming back anytime soon?
Can I add tasks to Windows Scheduled Tasks - Using PHP?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.