PHP increase memory_limit above 128M

24,569

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.

Share:
24,569
user2554863
Author by

user2554863

Updated on July 09, 2022

Comments

  • user2554863
    user2554863 almost 2 years

    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
    user2554863 over 10 years
    please look on my first post :-)
  • vee
    vee over 10 years
    @user2554863, hmm just the patch! Have you tried disabling it and testing the memory limit or is that going to be a pain?
  • user2554863
    user2554863 over 10 years
    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.
  • vee
    vee over 10 years
    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?
  • user2554863
    user2554863 over 10 years
    that is for an internal Project. I want to give the possibility to download a rrd-database (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(). Than I convert it to json and deliver it.
  • vee
    vee over 10 years
    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.
  • user2554863
    user2554863 over 10 years
    I get an php memory error PHP Fatal error: Allowed memory size of 134217728 bytes exhausted ... This is because the database is to big
  • vee
    vee over 10 years
    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?
  • user2554863
    user2554863 over 10 years
    I know this and I will try. But the fastest (and dirtiest :-)) solution was increasing the memory size (I was thinking).
  • user2554863
    user2554863 over 10 years