mocax Posted December 29, 2008 Share Posted December 29, 2008 i've got a website running on 2 load balanced web servers. using apache2 and php5 recently, as traffic picked up, i'm starting to get memory exhausted errors. originally the memory limit was 32M, i set it to 48M and the problem goes away for a while, but now it's getting those errors again. i inserted some code to log the memory usage and found that the code used up around 9MB most of the time, at certain times of the day, it balloons to nearly 30MB. After a spate of memory exhausted errors, the memory usage will drop back to the 9-11MB range for the rest of the day. i understand that apache is running in "prefork" mode for php, thus i see lots of httpd processes being created and destroyed when i monitor them with the "top" command. but the question is, does each httpd process "share" multiple php instances? if I ini_set("memory_limit","48M") and the page gets 50 hits simultaneously, will the 48MB gets shared between the 50 hits? any ways to mitigate the memory spikes? i can't increase the memory limit forever. or perhaps it's time to buy a couple more servers? Link to comment https://forums.phpfreaks.com/topic/138704-what-are-the-causes-for-memory-usage-spikes/ Share on other sites More sharing options...
corbin Posted December 29, 2008 Share Posted December 29, 2008 The memory usage goes up because things are using the memory. I know that sounded redundant, but think about it. Why are you having memory spikes? Probably because of traffic or a cron job or something. To answer your question, the memory_limit setting applies per script execution, not over a whole. Apache's memory would need to be limited for that. My suggestion would be to get more memory (how ever you would go about doing that), or try to optimize scripts to use less memory. Link to comment https://forums.phpfreaks.com/topic/138704-what-are-the-causes-for-memory-usage-spikes/#findComment-725201 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.