3

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

memory_limit 999M 999M

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

11
  • You edited the correct php.ini? (See phpinfo(), or php -i (note, that the different sapis (apache-module, cgi, cli, ...) use different php.inis)) You restarted your server? You ever thought about, why your scripts requires sooo much memory?!
    – KingCrunch
    Apr 3, 2012 at 20:33
  • 2
    memory_limit 999M 999M - surely you meant memory_limit 999M Apr 3, 2012 at 20:33
  • isn't your WordPress installation setting its own memory limit via ini_set('memory_limit', ...) ?
    – kuba
    Apr 3, 2012 at 20:35
  • 1
    how about optimising the script, you shouldn't need that much memory.
    – user557846
    Apr 3, 2012 at 20:36
  • Yeah I did edit the correct php.ini, it shows fine in phpinfo Apr 3, 2012 at 20:37

7 Answers 7

14

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.

4
  • Found a file called www.conf in /etc/nginx/fpm/pool.d. I would have never even thought to look there.
    – serialworm
    Dec 12, 2013 at 15:47
  • Maybe also look for /usr/local/lib/php.ini or /usr/local/php/lib/php.ini
    – iforce2d
    Aug 19, 2019 at 16:08
  • THANK YOU! This also drove me crazy :D
    – James
    Jul 30, 2020 at 21:13
  • In phpinfo() output there is "Additional .ini files parsed" key.
    – wesamly
    Sep 22, 2020 at 8:19
5

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))

2

I suggest you set this on the top of your script:

 ini_set("memory_limit","512M");

in the script that is consuming so much of your memory instead of allowing all scripts to consume so much memory. You can also put this in the .htaccess of your /wp-includes/

 php_value memory_limit 512M

More information and explanation here: http://www.mydigitallife.info/php-allowed-memory-size-exchausted-fatal-error/

5
  • Its already been set under /etc/php.ini so the limit is high enough, just wondering why it doesn't take effect in the script but the limit is shown under a phpinfo Apr 3, 2012 at 20:45
  • Because it can be overruled by wordpress in the wp-config.php file.
    – ArendE
    Apr 3, 2012 at 20:47
  • By using define('WP_MEMORY_LIMIT', '64M'); in that file for example.
    – ArendE
    Apr 3, 2012 at 20:49
  • Its not, already has both ini_set('memory_limit', '999M'); define('WP_MEMORY_LIMIT', '999M'); defined inside wp-config.php Apr 3, 2012 at 20:52
  • Well, it's very simple, there is still a limit somewhere. This could be set by your webhost, in some file, .htaccess etc. I suggest you try using all options to override the memory_limit without asking why it won't work as you want it or should be. Also look at the same question here stackoverflow.com/questions/3903363/… maybe it could be of some use :)
    – ArendE
    Apr 3, 2012 at 21:02
0

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.

5
  • The parameter is acquired, just doesn't work in wordpress, there isn't any overrides, did a grep with for ini_set and nada Apr 3, 2012 at 21:16
  • @DarrellDing you should grep php_value if you want to see if it's set in apache somewhere as well. Apr 3, 2012 at 21:21
  • My wordpress version (3.1.2) defines a file called wp-includes/default-constants.php that create a constant called WP_MEMORY_LIMIT. You can ovveride its value into wp-settings.php. Wordpress overwrite the php memory limit value setted into php.ini if it's smaller than the value you define with WP_MEMORY_LIMIT.
    – dAm2K
    Apr 3, 2012 at 21:36
  • 2
    Fixed, it wasn't WP_MEMORY_LIMIT, apparently wordpress uses WP_MAX_MEMORY_LIMIT as their admin max limit. Apr 3, 2012 at 21:40
  • 1
    Was the closest I got to an answer Apr 3, 2012 at 22:09
0

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
7
  • I've already tried that it still maxes out at 256 for some vague reason Apr 3, 2012 at 20:44
  • Did you restart apache? The code in your php.ini was invalid, too... Are you sure you don't have a second setting in your php.ini that is overwriting your custom line? Check for that, too... Apr 3, 2012 at 20:47
  • it shows memory limit 999m in phpinfo so that isn't the issue right now, I'm just wondering how come it doesn't work in wordpress. Wordpress's wp-config has been set to use up to 999 as well Apr 3, 2012 at 20:54
  • 1
    Did... you... restart... apache? Apr 3, 2012 at 20:59
  • Who manages your server? How much memory is currently available if you run "free -m" via the command line? Apr 3, 2012 at 21:01
0

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.

2
  • My problem is that I'm unable to increase the memory limit no matter what I do, not so much that I'm having an error Apr 3, 2012 at 20:58
  • @DarrellDing are you using any plugins like Memory Bump? You might want to check the setting there as well. Look all the way down the line: php.ini (and local php.ini if there are multiple), .htaccess, and search the php files for changes as well. Check with a small script to the side (just a quick script not in wordpress) to see if the php.ini and/or .htaccess files set it properly using ini_get('memory_limit') to check it. Apr 3, 2012 at 21:09
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.