Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP server ping seeming to cause 502 error
    text
    copied!<p>I setup a cron jon to go through my database, grab the ip and port of the Minecraft server via a whole loop and then ping it to get how many are online, this then stores into the database. </p> <p>Except I'm thinking there is a server that might be offline so the script hangs when it gets to it I think. My question is how can this be prevented and stop the 502 error that occurs;</p> <p><strong>502 Bad Gateway The server returned an invalid or incomplete response.</strong> </p> <p>status.class.php { <a href="https://github.com/FunnyItsElmo/PHP-Minecraft-Server-Status-Query/blob/master/MinecraftServerStatus/status.class.php" rel="nofollow">https://github.com/FunnyItsElmo/PHP-Minecraft-Server-Status-Query/blob/master/MinecraftServerStatus/status.class.php</a> }</p> <p>My Script:</p> <pre><code>&lt;?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 &gt;= 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-&gt;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 } } ?&gt; </code></pre> <p>EDIT: Intrestingly I did a little troubleshooting by setting the $current = 99 and ran the script it set all the servers to 99 / blah blah. But the page still returned a 502 after...?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload