I need Help with my website

09/23/2012 13:41 Avenger100#1
How to add status containing players online coded in PHP ?
09/23/2012 14:26 marlyandedsel#2
PHP Code:
<?php
require_once ('config.php');
            echo 
'<font style="color: #808080" size="2">SERVER:</font> ';
            
            
$fp = @fsockopen($serveraddress$serverport$errno$errstr1);
            if (!
$fp) {
                echo 
'<font style="color: red" size="2"><b>MAINT.</b></font><br />';
            }
            else
            {
                echo 
'<font style="color: YellowGreen" size="2"><b>ONLINE</b></font><br />';
                
fclose($fp);
            }             
    
$rank mysql_query("SELECT Online FROM Online WHERE Online > 0 || Online = 0");
    
$row mysql_fetch_array($rank);    
    
$tot $row['Online'];    
echo 
"<font color='#808080' size='2'><b>PLAYER:</font><font color='YellowGreen' size='2'>$tot</font>";

?>
09/23/2012 22:25 InstantAssassination#3
Quote:
Originally Posted by marlyandedsel View Post
PHP Code:
<?php
require_once ('config.php');
            echo 
'<font style="color: #808080" size="2">SERVER:</font> ';
            
            
$fp = @fsockopen($serveraddress$serverport$errno$errstr1);
            if (!
$fp) {
                echo 
'<font style="color: red" size="2"><b>MAINT.</b></font><br />';
            }
            else
            {
                echo 
'<font style="color: YellowGreen" size="2"><b>ONLINE</b></font><br />';
                
fclose($fp);
            }             
    
$rank mysql_query("SELECT Online FROM Online WHERE Online > 0 || Online = 0");
    
$row mysql_fetch_array($rank);    
    
$tot $row['Online'];    
echo 
"<font color='#808080' size='2'><b>PLAYER:</font><font color='YellowGreen' size='2'>$tot</font>";

?>
Or:

echo '<font style="color: lime"><b>Online</b></font><br />';
}
09/24/2012 12:24 Silent-Death#4
Quote:
Originally Posted by marlyandedsel View Post
PHP Code:
echo "<font color='#808080' size='2'><b>PLAYER:</font><font color='YellowGreen' size='2'>$tot</font>"
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:
PHP Code:
echo "<font color='#808080' size='2'><b>PLAYER:</font><font color='YellowGreen' size='2'>" $tot "</font>"
i believe it would work without doing this, but it's good practice.
09/24/2012 12:44 Korvacs#5
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.
09/24/2012 12:47 Silent-Death#6
also that
PHP Code:
$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 View Post
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
09/24/2012 13:05 Korvacs#7
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.

There is a far superior solution to this problem.
09/24/2012 13:14 Silent-Death#8
Quote:
Originally Posted by Korvacs View Post
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:
$connmysql_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. 

// manipulate your data here.

mysql_close($conn); 
09/24/2012 13:17 Korvacs#9
And again you dont solve the problem, you still rely on the fact that there is a timeout so this will never be instant.
09/24/2012 13:33 Silent-Death#10
Quote:
Originally Posted by Korvacs View Post
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?
09/24/2012 13:37 Korvacs#11
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.
09/24/2012 13:49 Silent-Death#12
ok well assuming you have that info stored in a variable already since you need to tell people the status of your server that is easy to implement.

PHP Code:
$sv_status True// server status variable (for example only)
if ($sv_status == TRUE) {
    
// data goes here.

09/24/2012 14:05 Korvacs#13
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.
09/24/2012 14:57 Silent-Death#14
Quote:
Originally Posted by Korvacs View Post
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_INETSOCK_STREAMSOL_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>";
    
  echo 
"<html><head></head><body>".
       
$text.
       
"</body></html>"
^ make sure you enable php_sockets.dll extension in php.ini

ofc you can alter this so instead of $text you have a bool and take it from there.
09/24/2012 15:13 Korvacs#15
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.