开发者

Another PHP out of memory problem using apache

I know it is an old question! But this time I have different situation.

I'm running php/mysql/apache on OpenSuse. I have set php with 128MB of memory. I don't have any RLimitMEM for apache.

Everything was fine, birds singing, flowers blossoming but once I restarted my apache then bad things happened!

I get PHP Fatal error: out of memory blah blah. All php powered applications that were working fine, now log this error. What happened? I tried memory_limit = 512M without any progress.

I'm confused why all my php files now throw this error except really small scripts. I tried phpinfo() and I really have 128MB of memory there. ( And I know that php apache ini setting is different from standalone php, I configured the correct one! ).

UPDATE:

exact php error samples:

[Mon Jul 25 04:22:25 2011] [error] [client 31.57.122.252] PHP Fatal error: Out of memory (allocated 1048576) (tried to allocate 491520 bytes) in /srv/www/htdocs/phpMyAdmin/libraries/common.inc.php on line 796

[Mon Jul 25 04:26:39 2011] [error] [client 31.57.122.252] PHP Fatal error: Out of memory (allocated 1048576) (tried to allocate 4 bytes) in /s开发者_JAVA百科rv/sbuta/library/Zend/Config/Ini.php on line 172

[Mon Jul 25 04:27:02 2011] [error] [client 31.57.122.252] PHP Fatal error: Out of memory (allocated 1048576) (tried to allocate 30720 bytes) in /srv/kode/library/Zend/Config/Ini.php on line 132


The problem is that there is no remaining physical memory! disabling some php or apache modules should fix the problem.

Step by step guide(:D) :

  • See if you have assigned php enough memory to use. usually at /etc/php5/apache2/php.ini search for memory_limit = ... . ( to test it, try putting a file with some strange name in your server with this content: <?php echo phpinfo();?> and see memory_limit value there ).
  • Test if you have any RLimitMEM in your apache settings. you can use cd /etc/apache2/ && grep -irn 'RLimitMEM' to find out.
  • See if you have any security limits for wwwrun ( or what ever user apache is running with ) in /etc/security/limits.conf
  • Try to exclude some unnecessary modules from php and/or apache.

Remember to restart apache after any change to test it.


Out of memory errors are the result of too much data stored in memory by your script. If you have a database with large data sets and pull data with fetchAll() instead of filtering you may run out of memory real quick. Another problem are objects where you store such large data sets. Last but not least you may have a loop that adds data to memory until it reaches the limit.

Check you scripts for places where you pull data and use XDebug. It can show you the increase on memory usage.

Update
Weird. The "out of memory" error you have here is not the error you usual get with the php memory_limit config (that has "memory exhausted") and since you have it with all apps this is even more clear.

There seems to be a limit imposed from the server environment which in your case is Apache. Maybe you can/must in fact set a max limit with RLimitMEM in your conf file. The default is to use the operating systems default which is your OpenSuse. If you suddenly have limitations for the user running your Apache module this may go to your Apache environment and then all the way to your PHP scripts which is finally complaining.

2nd Update
Time to isolate the problem. Because it began when you restarted your server and all your apps are experiencing this problem it has to be something in your server environment. Try to start and run phpMyAdmin with a default Apache config. If that already causes the error you have to look at your linux server.


PHP restarts its scripts for each reload; unless you script runs 24/7, it doesn’t get affected by continue uptime of Apache. When Apache’s memory usage grows, it either has more PHP processes or it just started to leak memory like normal with Apache and PHP.

Given you have an array that has 100000000 elements containing "foo" and you pass them to another function, that function call copies that array, effectively doubling PHP memory usage. By getting few calls like this, you can easily get a situation where your script is out of memory.


I had this issue on one of my servers and it turned out to be a problem with the Gnome3 desktop environment. On Debian and Ubuntu servers with 2 Gigs of memory or less, if you have the Gnome3 or Unity desktop environment installed, it eats up so much desktop memory that it starts using up RAM that apache needs which leads to the out of memory error.

Resolve the issue by installing either the "Gnome-Classic", Mate or LXDE desktop environment and logging into that instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜