views:

1237

answers:

4

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.

A: 

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).

Simon Groenewolt
A: 

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.

Amber
+4  A: 

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.

Pascal MARTIN
Interestingly enough, this article on drupal.org mentions that 96MB is recommended for sites using things like ImageAPI GD: http://drupal.org/node/29268
Amber
96MB ? Ouch! That's quite a bit much... I should try to say that to the guy responsible for the configuration of our servers, just to see his face ^^
Pascal MARTIN
I had my memory_limit set to 32M, a lot of customers complained about their image uploads 'blank screening'. When I checked it out in development, the error was just the same as the one the OP was getting, so I did in fact increase it (can't remember - to either 64M or 96M) and that solved the problem.
karim79
@karim79 : Thanks for the info ; I'll have to do some tests with big images, in this case, for the project I'm currently working on : better knowing this now than having our customers telling us "this doesn't work" -- especially, I'll have to compare between the GD and imagemagick backends...
Pascal MARTIN
The security aspect of the memory limit is to prevent your site from running out of control and causing too much havoc; the exact level is much less important than the fact there is a limit at all. I've never had a problem lifting the memory limit up to 64M or 96M on any of my drupal hosts.
Bevan
+1  A: 

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."

Jergason
Exactly the link I was about to post myself.
Bevan