|
PHP 可以通过exec函数执行shell命令,来获取ping时间。
代码示例:
echo 'PHP_INT_MAX : ' . PHP_INT_MAX . "
";
$ip = '115.29.237.28'; // IP地址
if (PATH_SEPARATOR==':') // linux
{
echo 'I am linux' . "
";
exec("ping -c 3 -w 5 $ip", $info);
echo 'linux info : ' . "
";
print_r($info);
$ping_time_line = end($info);
echo '
ping_time_line : ' . $ping_time_line . "
";
$ping_time = explode("=", $ping_time_line)[1];
$ping_time_min = explode("/", $ping_time)[0] / 1000.0;
$ping_time_avg = explode("/", $ping_time)[1] / 1000.0;
$ping_time_max = explode("/", $ping_time)[2] / 1000.0;
echo $ping_time_min . " " . $ping_time_avg . " " . $ping_time_max . "
";
}
else // windows
{
echo 'I am windows' . "
";
exec("ping -c 3 -w 5 $ip", $info);
echo 'windows info : ' . "
";
print_r($info);
$info_time = end($info);
echo '
info_time : ' . $info_time . "
";
}
|
|