4
全部使用, 我有一个使用fsockopen来侦测Minecraft服务器的脚本。我想知道是否有方法将其转换为使用cURL?PHP ping使用cURL的Minecraft服务器
下面是函数:
function pingserver($host, $port=25565, $timeout=30) {
//Set up our socket
$fp = fsockopen($host, $port, $errno, $errstr, $timeout);
if (!$fp) return false;
//Send 0xFE: Server list ping
fwrite($fp, "\xFE");
//Read as much data as we can (max packet size: 241 bytes)
$d = fread($fp, 256);
//Check we've got a 0xFF Disconnect
if ($d[0] != "\xFF") return false;
//Remove the packet ident (0xFF) and the short containing the length of the string
$d = substr($d, 3);
//Decode UCS-2 string
$d = mb_convert_encoding($d, 'auto', 'UCS-2');
//Split into array
$d = explode("\xA7", $d);
//Return an associative array of values
return array(
'motd' => $d[0],
'players' => intval($d[1]),
'max_players' => intval($d[2]));
}
看来,一个本地服务器,这就是为什么我想将它转化成卷曲这样我就可以在远程服务器上运行上运行时,此功能只适用。
这适用于远程服务器,我只是测试它。 – Jack 2012-04-07 21:11:04
嗯......我得到这个错误:'警告:fsockopen()[function.fsockopen]:无法连接到/home/user/public_html/mc.php中的xx.xx.xx.xx:25565(连接被拒绝)在线6' – 2012-04-08 03:19:36
听起来像你要么有某种防火墙,要么更可能连接到一个不好的主机/端口。 – Jack 2012-04-09 20:12:27