我想要一个PHP脚本,它允许你ping一个IP地址和一个端口号(ip:port).我发现了一个类似的脚本,但它只适用于网站,而不是ip:port.
<?php
function ping($host, $port, $timeout)
{
$tB = microtime(true);
$fP = fSockOpen($host, $port, $errno, $errstr, $timeout);
if (!$fP) { return "down"; }
$tA = microtime(true);
return round((($tA - $tB) * 1000), 0)." ms";
}
//Echoing it will display the ping if the host is up, if not it'll say "down".
echo ping("www.google.com", 80, 10);
?>
Run Code Online (Sandbox Code Playgroud)
我希望这个用于游戏服务器.
我的想法是我可以输入IP地址和端口号,然后我得到ping响应.