So I've been tinkering with the Gamer-Fusion 2.5 code (GF is an off shoot of the ExoFusion code). There is some good code in there but there is a LOT of code in that engine that is very poorly written and is indicative of the kind of coding you see when you get some of these "open source" games.
So lets look at some of the biggest mistakes and correct them with clean optimized code

throughout the game there are calls such as this:
$nump = @mysql_num_rows(mysql_query("select * from players"));
What this line is doing is getting the number of players the game has. The problem is it's loading the entire player table into memory and getting the number of rows. Say you had 25 fields in your player table and 1,000 players. Every time this code gets called you are loading ALL those fields and ALL those records into memory!!!! The line above was getting called in the footer.php file so on every page hit it was doing this. If you had 25 players online with 1,000 players in the database your performance would go down the tubes and your server would start to "lag".
Better way of doing it would be:
$nump = @mysql_fetch_array(mysql_query("select COUNT(*) from players"));
The above line is about 1000% faster with using almost very little memory or processing power! mySQL is highly optimized when using the COUNT(*) and it doesn't actually look at the records but instead looks at the header where the number of records is already stored

-----------------------------------------------
Lets say you are not using a template system but instead using print/echo statements. First of all DON'T USE PRINT. Use echo, it's faster, see the PHP documentation as to why it's faster.
A common thing to do is to open a table and display the data in the table....
$psel = mysql_query("select * from players");
$ctime = time();
while ($pl = mysql_fetch_array($psel)) {
$span = ($ctime - $pl[lpv]);
if ($span <= 180) {
if ($pl[rank] == Admin) {
echo "!$pl[tag]<A href=view.php?view=$pl[id]>$pl[user]</a> ($pl[id])<br>";
} else {
echo "$pl[tag]<A href=view.php?view=$pl[id]>$pl[user]</a> ($pl[id])<br>";
}
$numo = ($numo + 1);
}
}
The above code is used to display all the player's that are currently online (another very common function). There are a number of huge performance problems with the above code so lets get to optimizing
First item is, once again, we are loading ALL the fields from the player table but the code is only using 4. Only load in the fields you are going to use!!!! It then gets the current time and starts looping though all the players and anyone who has hit a page in the last 180 seconds gets displayed. This is unnecessary as a good query will do the same thing and do it much faster (mySQL can process data WAY faster then PHP can!).
So lets first rewrite the query to only bring us what we need:
$psel = mysql_query("SELECT id, user, tag, rank FROM players WHERE lpv >= UNIX_TIMESTAMP()-180");
There so now we will get a record set back with only the fields we need and those that have hit a page in the last 180 which we assume are online. Wait though there is more to optimize!!!
As the loop is going though the records it's echo'ing out the results. This again is a huge performance constraint. You can (and most people do) just turn on output buffering to make it faster but it's still poor code design. Instead of echo'ing the results out line by line it should put the results in a variable and echo the entire result in one swoop!
The HIGHLY optimized version:
$numo = 0;
$online = "";
$psel = mysql_query("SELECT id, user, tag, rank FROM players WHERE lpv >= UNIX_TIMESTAMP()-180");
while( $pl = mysql_fetch_array($psel) ) {
if ($pl['rank'] == 'Admin') {
$online .= "!$pl[tag]<A href=view.php?view=$pl[id]>$pl[user]</a> ($pl[id])<br>";
}
else {
$online .= "$pl[tag]<A href=view.php?view=$pl[id]>$pl[user]</a> ($pl[id])<br>";
}
$numo = ($numo + 1);
}
echo $online;
I don't have any performance bench marks but I would say the above optimized version is a good 200-300% faster then the original and will hold up better under high usage without affecting server performance

Hope ya all enjoyed this and found it useful
