我设置了一个cron jon来遍历我的数据库,通过整个循环获取Minecraft服务器的IP和端口,然后对其进行ping操作以获取多少在线,然后将其存储到数据库中。
除非我认为有一台服务器可能处于脱机状态,所以我认为该脚本在挂起时会挂起。我的问题是如何防止这种情况并阻止发生的502错误;
502错误的网关
服务器返回无效或不完整的响应。
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等等的脚本。但是...之后页面仍返回502。
最佳答案
为了全面分析您的问题,您将需要使用http://en.wikipedia.org/wiki/Wireshark之类的工具并遵循502发生的原因。
该脚本已经包含“离线检测”。我认为离线/在线问题不大。