PHP help, Cron.

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]

Try:

[php]$isOnline = @fsockopen($row[‘short_url’], 25565, $errorno, $errorstr, 5);[/php]

Instead of:

[php]$isOnline = @fsockopen(‘udp://’ . $row[‘short_url’], 25565, $errorno, $errorstr, 5);[/php]

That’s calling them all offline now. =/

Any idea guys? I really need this.

Can you post examples of what is in the $row[‘short_url’] value?

short_url is just the IP of the server. On the application form you place your IP there.

If you remove the @ from:

[php]$isOnline = @fsockopen(‘udp://’ . $row[‘short_url’], 25565, $errorno, $errorstr, 5);[/php]

What error(s) do you get?

I get none. It should doesn’t acknowledge port 25565. I have no server on and port 25565 is not even open but it continues to say my server is “online.”

If you echo out $errorno and $errorstr what do you get?

I’m not receiving any errors.

I’m very new to this though, I could be wrong. =/

By that do you mean you’ve checked the variables? Just to be 100% sure.

Yes. I think I will have to get a new fsockopen written. I’m really sad this isn’t working. All I need is this to work to continue working on my community. =/

P.S. Thanks for helping me so far, I’m really grateful for it.

Fixed, as the hosts problem.

Sponsor our Newsletter | Privacy Policy | Terms of Service