我使用此代码获取Time Ping:
<?php
$address = 'stackoverflow.com';
$ping = system("ping $address");
echo '<pre>';
echo $ping;
?>
输出是:
使用32字节数据ping stackoverflow.com [104.16.35.249]:
回复 从104.16.35.249:bytes = 32 time = 16ms TTL = 57
来自 104.16.35.249:bytes = 32 time = 15ms TTL = 57
来自104.16.35.249的回复:bytes = 32 time = 16ms TTL = 57
来自104.16.35.249的回复:bytes = 32 time = 15ms TTL = 57
对104.16.35.249的Ping统计数据:
数据包:已发送= 4,已收到 = 4,Lost = 0(0%损失),
大约往返时间(毫秒):
最小值= 15ms,最大值= 16ms,平均值= 15ms
最小值= 15ms,最大值= 16ms,平均值= 15ms
但是,我只是想获得平均时间Ping,该怎么做?
谢谢。
答案 0 :(得分:0)
您可以使用exec()
功能
$address = 'stackoverflow.com';
$ping = exec("ping $address");
$pingTime = explode(',',trim($ping));
echo $pingTime[2];
$time = explode("=",trim($pingTime[2]));
echo $time[1];