Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    112
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Ping Remote Servers

    Hi all.

    I run a website that uses several file servers to host some downloadable files. The problem is sometimes the file servers go off and I don't know until very much later. I want to make a script that can ping the list of these servers to see if they are online.

    I wrote a remote ftp function to ftp_login and if ftp_login fails, I assumed the file server is offline. Is this concept correct? I ran the script and all my results returned were "online"

    I'm also in a bit of a fix, most of the file servers are running on *nix servers but a couple are on NT. Will I have to do a different function for the NT servers? Here's the function code I have for the moment.

    Code:
    function sponsor_status($ftpadd,$ftpusername,$ftppassword)
    {
    	// set up basic connection
    	$conn_id = ftp_connect($ftpadd); 
    	
    	// login with username and password
    	$login_result = @ftp_login($conn_id, $ftpusername, $ftppassword); 
    
    	// check connection
    	if ((!$conn_id) || (!$login_result)) { 
          
    	  echo "<td class=\"error\"><strong>Offline</strong></td></tr>";
        } 
    
    	// Read flag file, success = file server online, else offline
    	else {
    		echo "<td><strong>Online</strong></td></tr>";
    	}
    
    // close the FTP stream 
    ftp_quit($conn_id);

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Maybe check out
    http://www.phpclasses.org/browse.html/package/1172.html
    Or one of these
    http://www.hotscripts.com/cgi-bin/se...status&catid=2

    I'm not sure that an ftp login is the way to go, since you can just ping them ... + no need to reinvent the wheel, right ?

  • #3
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    can you not use exec?

    PHP Code:

    exec
    ("ping server.com"); 
    and look at the output?

  • #4
    New Coder
    Join Date
    Jun 2002
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you can use the exec() command, however you need to specify the amount of times the ping goes especially on a *nix server. If you don't you can run into the possibility of continually pinging the machine and not knowing it. Just a little FYI

  • #5
    Regular Coder
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    112
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you. I tried to ping each server using the exec command but I didn't get any output.

    PHP Code:
    exec("ping ddg.gundamv3.com"); 
    Am I doing it right this way? Also, I had echo out some data on the same page, is that why there is no output from the ping?

    Thanks for helping.

  • #6
    New Coder
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php
        
    function ping($host)
        {
            
    $ip gethostbyname($host);
            
    $ping = `ping -c 1 -q $ip`;
            
    $res '1 packets transmitted, 1 packets recieved';
            if(
    strpos($ping$res))
                return 
    true;
            else
                return 
    false;
        }
    ?>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •