...

View Full Version : Ping Remote Servers



celestine
11-17-2003, 02:14 AM
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.



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);

raf
11-17-2003, 11:58 AM
Maybe check out
http://www.phpclasses.org/browse.html/package/1172.html
Or one of these
http://www.hotscripts.com/cgi-bin/search.cgi?bool=AND&query=server+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 ?

missing-score
11-17-2003, 12:17 PM
can you not use exec?




exec("ping server.com");



and look at the output?

Socraties
11-17-2003, 10:53 PM
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

celestine
11-18-2003, 12:40 AM
Thank you. I tried to ping each server using the exec command but I didn't get any output.


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.

Funkel
11-18-2003, 01:00 AM
<?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;
}
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum