PHP Memory limit not taking effect in normal php scripts

I’ve assigned the memory limit of php to 999m so it appears in phpinfo like

memory_limit 999M 999M

Read More

when I use phpinfo(); to show it.

Unfortunately when I try to run a fairly large script, it seems like the limit is 256M

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 40 bytes) in /xxx/wp-includes/wp-db.php on line 1403

Anyone have any ideas why or what I can do to increase the limit (and have it actually work)

If it helps I’m running centos5 32bit and with php running in fcgi mode

Related posts

Leave a Reply

7 comments

  1. I had a similar issue, for me it was an extra ini file that was loaded called “99-liip-developer.ini”. At the top of the file the memory_limit was defined at 265M, which overwrote the memory_limit defined in php.ini.

    Hope this helps anyone.

  2. Type php --ini to find the configuration paths.

    Change memory_limit to whatever value you need.
    Make sure that you are changing it on both these files: php.ini and conf.d/php-memory-limits.ini

    (in my case, I use -1 to have unlimited memory (of course, not unlimited but as much as my computer can handle))

  3. Create a php file called test.php, put inside:

    <?php
    phpinfo();
    ?>
    

    Check for “Configuration File (php.ini) Path” and “Loaded Configuration File” to see the correct php.ini path.
    Edit php.ini and search for memory_limit and set it to:

    memory_limit = 999M
    

    Check if you have more than one occurrency of memory_limit into the php.ini file. In the case, delete it.

    Stop apache, and then restart it (apachectl restart | apachectl graceful | kill -1 are not ok. Stop, then start).

    Recheck test.php to see if the new parameter got acquired.

  4. You can try putting this at the top of your file

    ini_set('memory_limit', '999M')
    

    How much system memory do you have available? Did you restart Apache after editing your php.ini file (I assume you have php installed as a module)?

    Try:

    sudo /etc/init.d/httpd restart
    
  5. Unsure, but this came up in the google search for me:

    http://wordpress.org/support/topic/plugin-cbnet-ping-optimizer-lots-of-errors-on-ping-optimizer-_help-please

    The ping optimizer was cramming a table full on the DB and clearing solved the problem. The error was almost the same:

    Fatal error: Allowed memory size of 268435456 bytes exhausted (tried
    to allocate 80 bytes) in
    /home/user1/public_html/domain/wp-includes/wp-db.php on line 1400

    So see if a plugin is doing the same, then clear it and log it on WP somewhere so it can be fixed if that is the problem.

  6. Make sure you server/virtual server in apache is not configured to overwrite PHP configuration. Even if you use:

    php_value memory_limit 512M
    

    Your server may have something like:

    php_value memory_limit 32M
    

    which will make your changes in php.ini useless.
    To fix this:

    • Either edit the php_value value in your server configuration.
    • Or remove it from your web server, so it uses PHP global settings.