View Full Version : Ping Remote Servers

11-17-2003, 03: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

11-17-2003, 12:58 PM
Maybe check out
Or one of these

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 ?

11-17-2003, 01:17 PM
can you not use exec?

exec("ping server.com");

and look at the output?

11-17-2003, 11: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

11-18-2003, 01: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.

11-18-2003, 02:00 AM
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;
return false;