Vitus Posted January 28, 2009 Share Posted January 28, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/142733-solved-overloading-server/ Share on other sites More sharing options...
corbin Posted January 28, 2009 Share Posted January 28, 2009 You either managed to write a script that causes a memory leak, or the PHP binary or some extension is corrupt (or in the case of an extension it could be badly written). Quote Link to comment https://forums.phpfreaks.com/topic/142733-solved-overloading-server/#findComment-748218 Share on other sites More sharing options...
DarkWater Posted January 28, 2009 Share Posted January 28, 2009 We'd need to see exactly what kind of code you've got going. Although the memory leak is actually kind of surprising to me (PHP is usually pretty good about that), it could, as corbin said, be an extension that's buggy. Quote Link to comment https://forums.phpfreaks.com/topic/142733-solved-overloading-server/#findComment-748219 Share on other sites More sharing options...
corbin Posted January 28, 2009 Share Posted January 28, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142733-solved-overloading-server/#findComment-748224 Share on other sites More sharing options...
Vitus Posted January 28, 2009 Author Share Posted January 28, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/142733-solved-overloading-server/#findComment-748564 Share on other sites More sharing options...
corbin Posted January 28, 2009 Share Posted January 28, 2009 "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. Quote Link to comment https://forums.phpfreaks.com/topic/142733-solved-overloading-server/#findComment-748672 Share on other sites More sharing options...
Vitus Posted January 28, 2009 Author Share Posted January 28, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/142733-solved-overloading-server/#findComment-748962 Share on other sites More sharing options...
corbin Posted January 28, 2009 Share Posted January 28, 2009 Hrmmm I doubt there are hashes of individual files. Quote Link to comment https://forums.phpfreaks.com/topic/142733-solved-overloading-server/#findComment-748967 Share on other sites More sharing options...
Vitus Posted January 28, 2009 Author Share Posted January 28, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/142733-solved-overloading-server/#findComment-748997 Share on other sites More sharing options...
trq Posted January 28, 2009 Share Posted January 28, 2009 Is it really hard to update? I figure i should evertually update anyway. No. And yes, you REALLY should. Quote Link to comment https://forums.phpfreaks.com/topic/142733-solved-overloading-server/#findComment-748999 Share on other sites More sharing options...
Vitus Posted January 28, 2009 Author Share Posted January 28, 2009 OK, after copying over the said files I ran three instances for over 800 requests with no complaints from PHP! I consider this solved. Thanks a bunch. Now I'm going to go ahaed and update PHP anyway. ~Vitus Quote Link to comment https://forums.phpfreaks.com/topic/142733-solved-overloading-server/#findComment-749010 Share on other sites More sharing options...
corbin Posted January 28, 2009 Share Posted January 28, 2009 Hrmmmm..... Well hopefully that was the problem ;p. Quote Link to comment https://forums.phpfreaks.com/topic/142733-solved-overloading-server/#findComment-749014 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.