Jump to content

Recommended Posts

Ok, here is the basis of my script:

I wrote a chat engine in PHP that takes $_GET info, processes the data and spits back the resulting actions.

 

Then I wrote a client website with AJAX (javascript on crack!) to send and receive the commands to and from the engine. So far everything worked OK.

 

Originally I created a new XMLHTTP object for each connection, but that was too inefficient so I strealined both the engine and the client, a basic session now goes like this:

 

Client to server:

?User=Guest&Pass=Guest&Stack=!NEWUSER*UserA*PassA

Server to Client:

!NEWUSERRESP*OK*UserA

Client to server:

?User=UserA&Pass=PassA&Stack=!INVITE*FriendA*ChatA!CHGSTAT*ChatA

Server to client:

!INVITERESP*OK!CHGSTATRESP*OK*ChatA

etc....

 

This way only one XMLHTTP object is used. However even when only sending commands once every 2500 ms, PHP.exe crashes on the server after about 40 commands or so. The script continues to run fine and the results of the command it crashed on do go through correctly(i believe) - and it never seems to be the same command it crashes on.

 

Is there something wrong with the concept of my code, shouldn't PHP be able to handle a new connection every 2.5 seconds? I watched the crashes on a HTTP watcher and it never really shows that the connections overlap at all. Infact, I have it programmed so for every client there is only one connection at a time.

 

The error I receive is: PHP.exe - Application Error

The instruction at "0x7c901010" referenced memory at "0x00000014". The memory could not be read.

Click OK to terminate the program.

 

Thanks in Advance

~Vitus

Link to comment
https://forums.phpfreaks.com/topic/142733-solved-overloading-server/
Share on other sites

It might not be a memory leak.  It could just be a corrupt file or something.

 

 

Edit:  Infact, with a popular program like PHP, I seriously doubt the problem is a memory leak.  (Memory leaks don't always cause programs to crash.  Infact, a lot of times, they just make memory usage go up since memory pointers are lost.)  But, a bad extension could have a memory problem.

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

"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?"

 

 

It would be released from execution right after it ran.  I suspect it's a corrupt php.exe or an extension still.  You could download a zip file of PHP and overwrite every file but php.ini.

I'll do that, is a hash of PHP.exe and related files available anywhere so I could double check to make sure they are not corrupt after I copy them?

 

i figure I'll replace the following:

php.exe

php4ts.dll

php4activescript.dll

php4apache.dll

php4apache2.dll

php4isapi.dll

php4nsapi.dll

php4pi3web.dll

phpsrvlt.dll

phpsrvlt.jar

 

~Vitus

Mostly I would just like a hash of PHP.exe version 4.3.6.6

 

I just found a copy at the muesum.php.net site, but can only find MD5s for newer versions (4.4.9 and up). Is it really hard to update? I figure i should evertually update anyway.

 

~Vitus

 

Edit:

stopped server,

copied over the said files anyway,

restarted server.

I'm going to run some tests now...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.