Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP increase memory_limit above 128M

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

like image 581
user2554863 Avatar asked Feb 26 '26 02:02

user2554863


1 Answers

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.

like image 122
vee Avatar answered Feb 27 '26 15:02

vee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!