PHP increase memory_limit above 128M

25.2k views Asked by At

I have running a Debian Squeeze with Standard Apache and PHP, installed via aptitude.

No I try to run :

<?php
 echo ini_get("memory_limit")."\n";
 ini_set("memory_limit","1024M");
 echo ini_get("memory_limit")."\n";
?>

Result: 128M 128M

What I have tried to change this behavior and some facts:

/etc/php5/apache2/php.ini:
safe_mode = Off
memory_limit = 128M

/etc/php5/apache2/conf.d/suhosin.ini:
[suhosin]
suhosin.memory_limit = 2048M

I can verify this settings with phpinfo();, after service apache2 restart.

Why I can not set the Memory Limit above 128M?

Note:

<?php
 echo ini_get("memory_limit")."\n";
 ini_set("memory_limit","127M");
 echo ini_get("memory_limit")."\n";
?>

Result: 128M 127M

Kind Regards

1

There are 1 answers

10
vee On

Changing of memory_limit is blocked by suhosin extension.

From the docs at: http://www.hardened-php.net/suhosin/configuration.html#suhosin.memory_limit

suhosin.memory_limit

Type: Integer Default: 0 As long scripts are not running within safe_mode they are free to change the memory_limit to whatever value they want. Suhosin changes this fact and disallows setting the memory_limit to a value greater than the one the script started with, when this option is left at 0. A value greater than 0 means that Suhosin will disallows scripts setting the memory_limit to a value above this configured hard limit. This is for example usefull if you want to run the script normaly with a limit of 16M but image processing scripts may raise it to 20M.

So with suhosin extension enabled, you need to change it and restart apache.