The engine.php script starts out with a few statements to guarantee critical arrays exist: (I haven't migrated the code to a database yet)
if(!isset($_SESSION['Users'])) { $_SESSION['Users'] = array('Guest' => 'Guest'); }
etc...
get User/Pass default Privileges:
$priv = 0;
$Username = $_GET['U'];
$Password = $_GET['P'];
split the stack into commands and args:
$Stack = $_GET['Stack'];
$commandblocks = split("!", $Stack);
for($c=0; $c <= (count($commandblocks)-1); $c++){
$args = split("\*", $commandblocks[$c]);
loop through commands and call functions
if ($priv >= 2){
switch($cmdtype) {
case "DELUSER":
DELUSER($args);
break;
case "LOGIN":
LOGIN();
break;
case etc........
and build output:
function LOGIN(){
global $Username;
$_SESSION['Active'][$Username] = 2; //2 = availible
echo "!LOGINRESP*OK*$Username";
}
function etc.....
I have 5 critical arrays that will eventually become databases:
$_SESSION['Users']
$Username => $Password
$_SESSION['Active']
$Username => $Chatroom (or 1 for logged out - 2 for available)
$_SESSION['Friends']
$Username => {$Key => $Friend1, $Key => $Friend2}
$_SESSION['Chat']
$ChatID => "<CHAT HTML>"
$_SESSION['Invite']
$Username => "!INVITERESP*FromFriend*ToCID"
The command that is called most often is the command that refreshes the User's Friendbox:
function FRIENDSTATUS(){
global $Username;
echo "!FRIENDRESP*";
if(!isset($_SESSION['Friends'][$Username])){
$_SESSION['Friends'][$Username] = array();
}
foreach($_SESSION['Friends'][$Username] as $Key => $Friend){
$Status = $_SESSION['Active'][$Friend];
echo "$Key-$Friend-$Status*";
}
}
I can't think of a memory leak really, because I use very few variables and most variables are reused or are (global / session). Also, I haven't really put in any other extensions (i.e. mysql, etc) almost every line is core PHP.
The only thought I have is that maybe when the script finishes its execution, it isn't removed from memory right away, in which case several may build up and collectively use too much memory. In which case, is there a setting that I can change to flush that sooner?
Thanks in Advance,
Vitus