Re: [PHP] re:Pinging from php srcipt From: Lars Torben Wilson (torben <email protected>)
Date: 08/15/00

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 <email protected>>                     Netmill iTech|
|http://www.coastnet.com/~torben            http://www.netmill.fi|
|Ph: 1 250 383-9735                             torben <email protected>|
+----------------------------------------------------------------+

-- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe <email protected> For additional commands, e-mail: php-general-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>