Increase PHP Memory limit (Apache, Drupal6)

烈酒焚心 提交于 2019-11-28 04:52:03

问题


I'm trying to run a Drupal installation on a shared hosting server. (I'm just subscribing to a provider - I don't own the box.)

I need to increase the PHP memory limit for my Apache server. I have tried

ini_set('memory_limit', '64M');

in settings.php (a file that is included in every request), but this causes Internal Server Error 500. If I take it out, I get this error:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 19456 bytes)...

Side question: 19456 is less than 33554432. Why is it saying that allowed size is exhausted?

I also tried putting this in on .htaccess:

 php_value memory_limit                 128M 

This had no effect.


回答1:


The error message you are getting :

Allowed memory size of 33554432 bytes exhausted (tried to allocate 19456 bytes)

Indicates that you are trying to allocate more than the 33554432 bytes you are allowed to use ; ie 32 MB :

; 33554432/1024/1024
        32

It indicates that the allocation that failed was when PHP tryied to allocate 19 Kbytes ; but there had already been almost 32MB allocated -- those allocations did not fail, as their total was less than 32 MB.

The "19456 bytes" part of the error message is not what is really relevant : what is relevant is that your memory_limit is set at 32 MB.


Considering the memory_limit is some kind of security, it would be strange that your hosting provider allows you to change its value...

If you are on shared hosting, it would mean that anyone on the server could get any amount of memory they want... Which would not be that nice for the other users on the same server !

BTW : 32MB is actually a quite reasonable value -- I've never seen a server configured to allow more than 32 MB for a web application... And the default value for PHP 5.2 seems to be 16 MB, according to the manual.
(And I've been working with Drupal for a couple of months)


About the error 500, I don't have a lot of ideas... One possibility might be that the safe_mode is activated, and that it doesn't allow setting the memory_limit at execution time.

The manual doesn't see to say much about that, but there is a bit of information under the max_execution_time directive :

You can not change this setting with ini_set() when running in safe mode. The only workaround is to turn off safe mode or by changing the time limit in the php.ini.

I suppose the same is true about memory_limit ; it would seem logical, anyway.




回答2:


Put it in your php.ini file. Ask your host to restart Apache. This node on drupal.org walks you through how to do it. If you have shared hosting, there are step-by-step guides on how to change your php.ini for most of the more popular providers on drupal.org. Just search for "PROVIDER_NAME increase memory limit."




回答3:


You need to verify with your hosting company how much memory they have allowed you as only they will be able to change it, if they won't increase it, then I suggest looking for a new host company.

However when it comes to drupal, you were correct to add

ini_set('memory_limit', 'xxxM');

to the settings.php file. (xxx = the required memory)

Drupal has a lot of fail safes, this is one of them and drupal stops you from exhausting your memory.

So check with you hosting company, get it increased and set your memory_limit in the settings.php file.

I usually just add this line at the very bottom of the script, but you can really add it anywhere.

Read this for other people that had a similar problem and had numerous methods to solve this in drupal.

http://drupal.org/node/29268

Good luck




回答4:


Ask your provider why it does not work. I would guess they limited the amount of memory you can use and do not allow it to be set any higher, or you are running inside a virtual host that simply does not have the amount of memory you request (That could be the cause of the error 500).




回答5:


Many shared hosting providers will not allow you to raise PHP's memory limit, as they don't want one site on a shared box hogging memory from other sites on the same machine. I'd recommend reading your hosting provider's FAQs and whatnot regarding PHP, it may list any such limitation there.

Side question: 19456 is less than 33554432. Why is it saying that allowed size is exhausted?

The smaller number is just the size of the request which caused the total allocated amount to go over the limit - not the actual total across all allocation requests. So if 33540000 bytes were already allocated, and another object of size 19456 were requested, then you'd get that message.




回答6:


If you're setting memory_limit and getting out of memory errors less than the maximum, one culprit lies with the upstream system spawning your process: Apache.

In Apache configuration (/usr/local/apache/conf/httpd.conf), you'll find a directive that sets an upper limit for all child processes that handle requests (and Drupal is running in such processes). A given Apache server may handle multiple customers (you and some number of others). If they allowed one customer to hog all the memory, everyone else would be having a BadTime(tm). To avoid that situation, they'll cap how much memory each such process can have.

For example:

# rlimits, do not modify
#  Setting single-process size 
#RLimitMEM 85643200 104857600
RLimitMEM 134217728 537395200

Here, I've commented out the original values set by my hosting service and increased them.

Of course, if you are on a shared server, then it's highly unlikely you can change this configuration. In fact, this is likely the configuration your host provider would change.

FWIW, Host Gator seems to give you ~80Mb per process. The PHP runtime seems to take ~16Mb.



来源:https://stackoverflow.com/questions/1386815/increase-php-memory-limit-apache-drupal6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!