I use this code to get Time Ping :
<?php
$address = 'stackoverflow.com';
$ping = system("ping $address");
echo '<pre>';
echo $ping;
?>
And the output is :
Pinging stackoverflow.com [104.16.35.249] with 32 bytes of data:
Reply from 104.16.35.249: bytes=32 time=16ms TTL=57
Reply from 104.16.35.249: bytes=32 time=15ms TTL=57
Reply from 104.16.35.249: bytes=32 time=16ms TTL=57
Reply from 104.16.35.249: bytes=32 time=15ms TTL=57
Ping statistics for 104.16.35.249:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 15ms, Maximum = 16ms, Average = 15ms
Minimum = 15ms, Maximum = 16ms, Average = 15ms
But, I just want to get Average Time Ping, how to do that ?
Thank you.
You can do it using exec()
function
$address = 'stackoverflow.com';
$ping = exec("ping $address");
$pingTime = explode(',',trim($ping));
echo $pingTime[2];
$time = explode("=",trim($pingTime[2]));
echo $time[1];