Re: re:Pinging from php srcipt

From: Date: Wed, 16 Aug 2000 03:27:22 +0000
Subject: Re: re:Pinging from php srcipt
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-11905@lists.php.net to get a copy of this message
Joseph H Blythe writes: > Cool thanks :-) > > I have played around with this after reading the ping man page. Does anyone > know if you can get ping to output only the average and nothing else, or > will I have to write a complex script to parse the output to only grab the > average? > > > Thanks again, > > > Joseph Blythe My local version of ping doesn't offer this option, but here's a (*very*) quick-and-dirty method: <?php $host = 'www.thebuttlesschaps.com'; if (!$result = ping -c 3 -q $host) { echo "Unknown host\n"; } else { /* The only slashes that show up ni the output are those right * around the information we want, so split it up on that. */ $result = explode('/', $result); $result = $result[3]; echo "Average ping time: $result\n"; } ?> Cheers, Torben -- +----------------------------------------------------------------+ |Torben Wilson <torben@php.net> Netmill iTech| |http://www.coastnet.com/~torben http://www.netmill.fi| |Ph: 1 250 383-9735 torben@netmill.fi| +----------------------------------------------------------------+

« previous php.general (#11905) next »