PHP Memory Usage

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
cysten
Forum Newbie
Posts: 2
Joined: Tue Nov 09, 2010 1:28 pm

PHP Memory Usage

Post by cysten »

Hi I just have a quick question.

A client of mine is having memory problems with his drupal site. His site uses a lot of memory. Some of his pages take 100 mb of memory to load. Currently he has his php.ini memory setting set to 250 mb. Some times it takes a very long time for his pages to display to his users.

So what happens if 5 users click to load a page at the same time? Does the 250 mb limit apply to all of them combined? I.E. the server returns an error? Or does it apply to each page click only, allowing the 250 mb memory limit to be surpassed. My client says his server crashes periodically every five months or so. Could this be related?

Thanks,
Cheers.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: PHP Memory Usage

Post by Darhazer »

memory_limit is the amount of memory single script may use. But if you have several scripts eating your memory, you will end up with no memory available, OS constantly swaping which leads to poor performance, and eventually system crashing. So it's best to check what eats so much memory. I've personally had similar issue 2 times:
the first one was with a large tree structure (about 100,000 nodes) which (because of an inefficient code) was copied 3 times in the memory
the second was with loading the entire table from the database in memory, under specific circumstances (in which no rows have to be loaded at all)

XHProf is a good and easy to use profiler. Log single run of the page and see at what point most of the memory is consumed. Then you can post that part of the code so we can give you further help.
cysten
Forum Newbie
Posts: 2
Joined: Tue Nov 09, 2010 1:28 pm

Re: PHP Memory Usage

Post by cysten »

Thanks so much!

How exactly does it slow down performance? I've noticed on the devel performance module that some of the users only have to wait .5 sec for the front page to load while others have to wait 20 or 30 sec!Could this be the cause? Or could it be their connection? I've also noticed that many of the users with poor display times were from poor European countries.

I suspect that the 100 mb is normal. My client has a number of resource demanding modules (like Imagecache) that he is not willing to part with. So if enough people logged on at the same time this would crash the server correct?
devilinc
Forum Newbie
Posts: 16
Joined: Fri Nov 12, 2010 1:07 am

Re: PHP Memory Usage

Post by devilinc »

i think its more to do with some memory leak u have in code....script can consume but i dont think this much unless it is a very very very big system he has implemented....i had ran into one of such similar issues.....it had to do with my code....and i corrected it....a massive memory leak :D
Post Reply