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!

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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!
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.
Phil PhillipsDirector of DevOpsCommented:
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.
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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

Still desperately confused!
billy_howardAuthor Commented:

It's only when you log in..

Just logged into the system ( 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.






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

		list($login, $last_login, $id) = $main->check_LoginDetails($_POST['username'], $_POST['password']);
			$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 {

Open in new window

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
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.