3

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

user2554863
  • 61
  • 1
  • 2
  • 5

1 Answers1

2

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.

vee
  • 38,255
  • 7
  • 74
  • 78
  • please look on my first post :-) – user2554863 Aug 09 '13 at 06:59
  • @user2554863, hmm just the patch! Have you tried disabling it and testing the memory limit or is that going to be a pain? – vee Aug 09 '13 at 07:05
  • Hi, I have comented out: `extension=suhosin.so` in /etc/php5/apache2/conf.d/suhosin.ini. After an Apache restart it works. Suhosin version is: Suhosin Patch 0.9.9.1. Do you have any help? I do not want to leave it off. – user2554863 Aug 09 '13 at 07:15
  • Don't really know how to help you except suggesting you to set higher memory limit and restart apache since you want to set higher memory limit. Why exactly do you want to set higher memory limit, may I know? – vee Aug 09 '13 at 07:17
  • that is for an internal Project. I want to give the possibility to download a rrd-database (http://oss.oetiker.ch/rrdtool/). Therefore a time period can be given and I fetch the data within this period from the database with [`rrd_fetch()`](http://php.net/manual/en/function.rrd-fetch.php). Than I convert it to json and deliver it. – user2554863 Aug 09 '13 at 07:29
  • Not possible to improve the script at all? If so, very bad option I am giving you next, have you tried with max_execution_time(-1) or a sensible number to allow the script to complete it's task? only if this script runs at a time when the server has minimal load, probably during off hours. – vee Aug 09 '13 at 07:33
  • I get an php memory error `PHP Fatal error: Allowed memory size of 134217728 bytes exhausted ...` This is because the database is to big – user2554863 Aug 09 '13 at 07:41
  • Well... `rrd_fetch()` seems to have `start` and `end` parameters, so the best thing to do would be download and process in smaller chunks. Have you not tried that? – vee Aug 09 '13 at 07:43
  • I know this and I will try. But the fastest (and dirtiest :-)) solution was increasing the memory size (I was thinking). – user2554863 Aug 09 '13 at 07:47
  • please look on http://stackoverflow.com/questions/18146965/php-rrd-fetch-out-of-memory – user2554863 Aug 09 '13 at 12:46