Increase PHP memory limit (Apache, Drupal6)

I am trying to run a Drupal installation on a shared hosting server. (I just signed up for a provider - I don't have a box.)

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

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

in settings.php (the file that is included in each request), but this causes an internal 500 server error. If I select this, 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 does he say that the allowed size has been exhausted?

I also tried including this in .htaccess:

  php_value memory_limit 128M 

It had no effect.

+4
source share
6 answers

The error message you receive is:

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

Indicates that you are trying to allocate more than 33554432 bytes that you can use; those. 32 MB:

 ; 33554432/1024/1024 32 

This indicates that a failed distribution occurred when PHP attempted to allocate 19 KB; but no more than 32 MB was allocated - these distributions did not fail, since their sum was less than 32 MB.

Part of the error message "19456 bytes" is not true: the important thing is that your memory_limit set to 32 MB.


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

If you are on a shared hosting, this will mean that anyone on the server can get any required memory ... What would it not be so nice for other users on the same server!

BTW: 32 MB is actually quite a reasonable value - I have 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 worked with Drupal for several months)


About the 500 error, I donโ€™t have many ideas ... One of the possibilities may be that safe_mode activated, and that it does not allow setting memory_limit at runtime.

The manual does not say much about this, but there is some information in the max_execution_time directive:

You cannot change this parameter with ini_set() when working in safe mode. The only workaround is to disable safe mode or by changing the limit time in php.ini.

I believe the same is true for memory_limit ; still logical.

+10
source

Put it in the php.ini file. Have your host restart Apache. This node on drupal.org will follow how to do this. If you have shared hosting, there are step-by-step tutorials on how to change php.ini for most of the most popular providers at drupal.org. Just search for "PROVIDER_NAME" by increasing the memory limit.

+1
source

You need to confirm with your hosting company how much memory they have allowed you, because only they can change it, if they do not increase it, then I suggest looking for a new hosting company.

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

 ini_set('memory_limit', 'xxxM'); 

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

Drupal has many crash safes, this is one of them, and drupal stops you from exhausting memory.

So, check your hosting company, increase it and set memory_limit in the settings.php file.

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

Read this for other people who had a similar problem, and they had many ways to solve this problem in drupal.

http://drupal.org/node/29268

Good luck.

+1
source

Ask your provider why it does not work. I would suggest that they limit the amount of memory that you can use and donโ€™t let it set a higher level, or you are working on a virtual host that just does not have the amount of requested memory (this could be the cause of error 500).

0
source

Many public hosting providers will not allow you to increase the memory limit of PHP, because they do not want one site in the shared folder to clog memory from other sites on the same computer. I would recommend reading the frequently asked questions about your hosting provider and regarding PHP, it can indicate any such restriction.

Side question: 19456 is less than 33554432. Why does he say that the allowed size has been exhausted?

A smaller number is simply the size of the request, due to which the total amount allocated exceeds the limit, and not the actual amount in all distribution requests. Therefore, if 33540000 bytes have already been allocated, and another object of size 19456 has been requested, you will receive this message.

0
source

If you set memory_limit and exit errors in memory less than the maximum value, one of the culprits is that the upstream system starts your process: Apache.

In the Apache configuration ( /usr/local/apache/conf/httpd.conf ) you will find a directive that sets an upper limit for all child processes that process requests (and Drupal works in such processes). This Apache server can handle several clients (you and some others). If they allowed one client to swing all the memory, all the others would have BadTime (tm). To avoid this situation, they will close the amount of memory that each such process can have.

For instance:

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

Here I commented on the initial values โ€‹โ€‹set by my hosting service, and increased them.

Of course, if you use a shared server, then you are unlikely to be able to change this configuration. In fact, this is likely to change your host provider.

FWIW, Host Gator seems to give you ~ 80Mb per process. PHP run time is ~ 16 MB.

0
source

All Articles