one little thing in this code, other then that the process seems about right.
separate php code from html code in echo using quotation marks and dots. same principle as in c# using the plus sign, but in php it's a dot:
That's actually one of the worst ways of doing it as if the server is down you have to wait, and wait, and wait for the script to time out before the page loads.
$rank = mysql_query("SELECT Online FROM Online WHERE Online > 0 || Online = 0");
seems a bit dodgy.. don't get me wrong, it would work if you would have a field named online in the table online, but i would guess you would want to get the char names out of that table. this would also change your where clause field name, and not sure why you would want to take out empty field or have empty fields in there for that matter. the if (!$fp) already checks for that so i would just remove the || Online = 0 .
Quote:
Originally Posted by Korvacs
That's actually one of the worst ways of doing it as if the website is down you have to wait, and wait, and wait for the script to time out before the page loads.
" if the website is down" sorry, do you mean the database?
anyway.. edit max_execution_time value in the php.ini or temper with set_time_limit()
also if the database is down you check that on connection
Sorry, definitely meant server, im at work! And even when editing max_execution_time you dont solve this problem as then it cuts the entire script short, not just the attempt to connects to the remote port.
And even when editing max_execution_time you dont solve this problem as then it cuts the entire script short
i agree. but again, a simple mysql connection check would do the trick:
PHP Code:
$conn= mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$conn) {
die('sql is down: ' . mysql_error()); // edit if you don't want to post the mysql error out.
}
echo 'connection established'; // edit out or whatnot.
And again you dont solve the problem, you still rely on the fact that there is a timeout so this will never be instant.
well you could lower the mysql connection time or optimize the MySQL response time (disable MySQL indexes. disable DNS hostname lookup, activate query cache), but you still have to get a response from the database (and time for that is requires) in order to proceed with data in your page.
of course there are many advanced techniques you can use on massive amounts of data, but would this really be required on a co pserver website?
Your looking at this from the wrong direction, you believe the website should check with the game server to see if its online.... this isnt correct.
The website should be told that the server is online...by the server. Once you look at it from that perspective then the solution is obvious and theres suddenly no issues with timeouts.
The best solution is to have the game server update a database stored on the webserver, with a timestamp of when it last wrote, your page then checks the timestamp and if the timestamp is more than say...2 - 5 minutes out of date then you know the server is down. All online player counts and similar statistics are also stored on the webservers database.
The best solution is to have the game server update a database stored on the webserver, with a timestamp of when it last wrote, your page then checks the timestamp and if the timestamp is more than say...2 - 5 minutes out of date then you know the server is down. All online player counts and similar statistics are also stored on the webservers database.
wouldn't that defeat the purpose of going around the time it takes you to connect to the database and check a table from the webpage?
maybe it would be better to talk directly to the server:
PHP Code:
$address=$_SERVER['REMOTE_ADDR'];
if (isset($_REQUEST['port']) and
(!strlen($_REQUEST['port'])==0))
$port=$_REQUEST['port'];
else
unset($port);
if (isset($port) and
($socket=socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) and
(socket_connect($socket, $address, $port)))
{
$text="Connection ok on IP $address, port $port";
socket_close($socket);
}
else
$text="Unable to connect<pre>".socket_strerror(socket_last_error())."</pre>";
No it wouldnt defeat the purpose, what your trying to avoid is a timeout, that hangs up the page making people unable to use your website, what your want is for people to be able to use your website no matter what the circumstance. The system i describe works no matter what the circumstance without any timeouts. The website being out of date by 60 seconds isnt a concern lol.