PHP Ping脚本错误500
脚本正在工作,但若主机尝试ping不应答或获取请求超时,则服务器会出现错误500 如果可能的话,我想在php代码中解决这个问题 我想要的是,若主机在ping上超时,那个么只需显示“超时”,而不显示来自服务器的错误PHP Ping脚本错误500,php,timeout,ping,Php,Timeout,Ping,脚本正在工作,但若主机尝试ping不应答或获取请求超时,则服务器会出现错误500 如果可能的话,我想在php代码中解决这个问题 我想要的是,若主机在ping上超时,那个么只需显示“超时”,而不显示来自服务器的错误 <html> <head> <meta http-equiv="refresh" content="30" > <?php error_reporting(0); // Turn off all erro
<html>
<head>
<meta http-equiv="refresh" content="30" >
<?php
error_reporting(0); // Turn off all error reporting
?>
</head>
<body bgcolor="#222222">
<center>
<table width="100%" height="" border="1" cellpadding="3" style="color:black">
<tr>
<td align = center width="150"
<?php
function icmp_checksum($data) {
if (strlen($data) % 2) {
$data .= "\x00";
}
$bit = unpack('n*', $data);
$sum = array_sum($bit);
while ($sum >> 16) {
$sum = ($sum >> 16) + ($sum & 0xffff);
}
return pack('n*', ~$sum);
}
function ping($host) {
$tmp = "\x08\x00\x00\x00\x00\x00\x00\x00PingTest";
$checksum = icmp_checksum($tmp);
$package = "\x08\x00".$checksum."\x00\x00\x00\x00PingTest";
$socket = socket_create(AF_INET, SOCK_RAW, 1);
socket_connect($socket, $host, null);
$timer = microtime(1);
socket_send($socket, $package, strlen($package), 0);
if (socket_read($socket, 255)) {
return round((microtime(1) - $timer) * 1000, 2);
}
}
$host="telia.se";
$pingtime = ping ($host);
if ($pingtime == FALSE)
echo "bgcolor='red" ."' >";
else if ($pingtime > 40)
echo "bgcolor='yellow" ."' >";
else
echo "bgcolor='lime" ."' >";
echo ("<h2><B>$host</b></h2>");
echo $pingtime."ms";
?>
</td>
</tr>
</table>
</center>
</body>
</html>
只有ping成功时,函数才会返回值。更新它以在失败时返回值:
if (socket_read($socket, 255)) {
return round((microtime(1) - $timer) * 1000, 2);
} else {
return false;
}
只有ping成功时,函数才会返回值。更新它以在失败时返回值:
if (socket_read($socket, 255)) {
return round((microtime(1) - $timer) * 1000, 2);
} else {
return false;
}
您的确切错误是什么?错误500内部服务器错误您的确切错误是什么?错误500内部服务器错误