我设置了一个 cron jon 来遍历我的数据库,通过整个循环获取 Minecraft 服务器的 ip 和端口,然后 ping 它以获取有多少在线,然后将其存储到数据库中。
除了我认为有一个服务器可能处于脱机状态,所以我认为脚本在到达它时会挂起。我的问题是如何防止并阻止发生的 502 错误;
502 Bad Gateway 服务器返回无效或不完整的响应。
status.class.php { https://github.com/FunnyItsElmo/PHP-Minecraft-Server-Status-Query/blob/master/MinecraftServerStatus/status.class.php }
我的脚本:
<?php
require('../config.php');
require ('../lib/status.class.php');
$SQL = mysql_query("SELECT id, ip, port FROM servers");
while($row = mysql_fetch_assoc($SQL)){
//Fetch the server info
$id = $row['id'];
$ip = $row['ip'];
$port = $row['port'];
echo $id.' - '.$ip.' - '.$port;
$PSQL = mysql_query("SELECT * FROM server_ping WHERE server_id = '$id' AND pinged >= now() - INTERVAL 5 MINUTE");
$Pnum = mysql_num_rows($PSQL);
if($Pnum == 0){
//If the server was not pinged within the last 5 minutes
//Ping the server
$status = new MinecraftServerStatus();
$response = $status->getStatus($ip, $port);
if($response) {
$current = $response['players'];
$max = $response['maxplayers'];
} else {
$current = '--';
$max = '--';
}
//Check if the server is in the list
$BSQL = mysql_query("SELECT * FROM server_ping WHERE server_id = '$id'");
$Bnum = mysql_num_rows($BSQL);
if($Bnum == 0){
//If the server has never been added - add it
$ASQL = mysql_query("INSERT INTO server_ping (server_id, current, max)
VALUES ('$id', '$current', '$max')");
} else {
//If the server has been added - update it
$ASQL = mysql_query("UPDATE server_ping SET current = '$current', max = '$max' WHERE server_id = '$id'");
}
} else {
//If the server was pinged within the last 5 minutes
}
}
?>
编辑:有趣的是,我通过设置 $current = 99 进行了一些故障排除,并运行了将所有服务器设置为 99 / blah blah 的脚本。但是页面仍然返回 502...?