pinging host measured in micro seconds


You have a requirement to capture network speed, in microseconds.

The required speed was less than 0.25 of a second (or quarter of second).



We use PHP to capture the current time in microseconds. Run a system ping command. Capture the new time and minus one from the other.



Here’s the PHP code, using the microtime function and a simple ping.


list($usec, $sec)=
explode(" ",microtime());

$thisDate=sprintf("%f", ($usec+$sec));


system("ping -c1 $host > /dev/null 2>&1",$response);

if($response==0) {

list($usec, $sec)=explode(" ",microtime());

$nextDate=sprintf("%f", ($usec+$sec));


} else {

print("ping failed to host: $hostn");



Here is a run through:

$ php -q pingHost.php bagend
$ php -q pingHost.php bagend
$ php -q pingHost.php bagend
$ php -q pingHost.php bagend



[tags]UNIX, Network testing, ping, PHP, microtime, PHP Coding School[/tags]


If you have found my website useful, please consider buying me a coffee below 😉

Leave a Reply

Your email address will not be published. Required fields are marked *