Hey guys, I’m having trouble with this code. It’s suppose to check if a server on port 25565 is online, sadly it’s not checking with the 25565 and only checking to see if it’s receiving information from the IP. Cron Jobs is setup and working correctly, but this code is not working.
It has to do with the fsockopen area, that’s all I know sadly.
[php]<?php
// Initialize the $CONF array and define custom data
$CONF = array();
define(‘ATSPHP’, 1);
require_once("/info/you/don’t/need");
require_once("/info/you/don’t/need");
$DB = “sql_{$CONF[‘sql’]}”;
$DB = new $DB;
$DB->connect($CONF[‘sql_host’], $CONF[‘sql_username’], $CONF[‘sql_password’], $CONF[‘sql_database’]);
$request = $DB->query(“SELECT username, short_url, uptime_data FROM {$CONF[‘sql_prefix’]}_sites WHERE active = 1”,
FILE, LINE);
while ($row = mysql_fetch_assoc($request)) {
$isOnline = @fsockopen(‘udp://’ . $row[‘short_url’], 25565, $errorno, $errorstr, 5);
list(, , $numOnline, $numOffline) = explode(’,’, $row[‘uptime_data’]);
if ($isOnline) {
$numOnline++;
fclose($isOnline);
$isOnline = ‘online’;
} else {
$numOffline++;
$isOnline = ‘offline’;
}
$total = $numOnline + $numOffline;
$uptime = ($total == 0 ? 100 : round(($numOnline / $total) * 100));
$uptimeData = $isOnline . ',' . $uptime . ',' . $numOnline . ',' . $numOffline;
$DB->query('UPDATE ' . $CONF['sql_prefix'] . '_sites SET uptime_data = \'' . $uptimeData . '\' WHERE username = \'' . $row['username'] . '\'',
__FILE__, __LINE__);
}
$DB->close();
?>[/php]