• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 542
  • Last Modified:

php application leaking memory..

Hi there Experts,

I am really hoping you guys will do me a wonderfull 11th hour save here.

I am just finishing up a bit of code to go live for a demonstration tomorrow to some customers. I have been working on this code for the last month or so, and it's my first real forrey into object orientated code, and the likes.

When running the app on my local machine (with an XAMPP installation) the suite runs nicely, smoothly everything is golden and lovely. My XAMPP installation is using standard settings, no worries at all.

SO I am extremely confused as to why, when I upload the same script using the same database to my prodution server (CentOS) the entire application would seem to stop working completely.


Basically what I get is this:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 33566033 bytes) in /home/tom/domains/***.org/public_html/***/lib/core.php on line 337

I can happily give you the URL of the system if you would like. Hell at this point I can email you the dammed source code.

The really frustrating thing is that line 337 is just this:

return preg_replace($pattern, $replacement, $string);

And that's doing a replacement from a set of sanitization functions that I have literally been using for years. If I remove that line then it jumps to line 177 of the same file, which again is nothing that exiting.

Really I am confused as hell.

The only potential difference is that my xampp install is using PHP 5.3.1 and my server is using 5.2.12.

Both servers have memory_limit's set to 128M.

Oh dear lordy please help experts!

0
billy_howard
Asked:
billy_howard
1 Solution
 
Terry WoodsIT GuruCommented:
Regular expressions can I think be quite resource intensive if not written carefully. If you can figure out what pattern is being used with the preg_replace command, and what is being targeted with it within the string, I may be able to suggest an efficiency improvement for the pattern.

Of course, it might just be a bug in PHP, or something else. Further input by experts would be good!
0
 
Terry WoodsIT GuruCommented:
Perhaps the easiest thing to try to start with would be to increase the memory limit and see if the problem stops happening.
0
 
Phil PhillipsDirector of DevOps & Quality AssuranceCommented:
I agree with TerryAtOpus that you should try upping the memory limit first.  It's likely that memory is being allocated differently on the CentOS system vs. the Windows(?) one.
0
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
billy_howardAuthor Commented:
Upped the memory limit all the way to 500m and thats still not doing anything..

Still desperately confused!
0
 
billy_howardAuthor Commented:
AHH!!!

It's only when you log in..

Just logged into the system (www.inca-internet.com/rookway/) and it's only when you try and login to the system that this throws the memory error, after that if you refresh the page it works fine!

Login code attached.


<?php

require("lib/lib.php");

if($main->is_LoggedIn()){
	$main->redirect("index.php");
	die();
}

if(!isset($_POST['username'])){

	$main->get_LoginForm();

} else {
	if(isset($_POST['username']) && isset($_POST['password'])){

		list($login, $last_login, $id) = $main->check_LoginDetails($_POST['username'], $_POST['password']);
		if($login===false){
			$main->get_LoginForm(false); // FALSE denotes login was unsucessfull.
		} elseif($login===true){
			// Login sucessfull.
			$main->set_Login($_POST['username'], $id);
			
			$main->get_LoginForm(true, $last_login);
		}
	} else {
		
		$main->get_loginForm();
		
	}
}

Open in new window

0
 
Slick812Commented:
hello billy_howard, , I do not see anything that looks like a memory hog in your log In. In a class I made, I had several for loops, and I used too much memory. I found the problem by using the PHP call -
echo 'Pos1 '.memory_get_usage();

in several many places to see where memory was increasing. Then I used the
unset($loopVar);
to clear several many variables of their memory. But be sure to only unset something when it will not be accessed again.
And if your PHP is not where you can use  echo , you can write the memory_get_usage() to an apending log file, to use for error detection.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now