views:

59

answers:

2

Hi,

I am wondering what would the best way to let visitors of a website ping various remote servers. Example: I am a visitor, I choose from a lsit of locations Paris, France and the script would ping from my location to Paris and return an average of x number of ping attempts.

Any ideas?

A: 
$ping_handle = popen("/sbin/ping -c 10 google.com","r");
while($line = fgets($ping_handle))
{
    echo $line,"\n";
}
deadkarma
This is *nix dependent, though.
George Edison
I don't see any results, $line seems empty ?
skarama
A: 

I'm not sure there's a "best" way, but there are definitely a few ways you could manage it.

  • Use the Net_Ping PEAR package
  • Execute the ping command locally using exec() or something similar, ie exec("ping $stuff",$output);. This obviously couples you to an external program, which can be undesirable, and you'd have to parse the output.
  • Implement your own ping using socket handlers. Probably not the easiest method.

It sounds like you actually want more than just the usual "Is the server alive?" type of check, so if it was me, I'd go with the PEAR package. It's already got some result parsing built in. I'm not a huge fan of PEAR, but there's no point in re-inventing the wheel.

zombat
Ţhanks a lot, I'll give that a try
skarama