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

Darrell Ding
  • 73
  • 1
  • 1
  • 6
  • 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 03 '12 at 20:33
  • 2
    `memory_limit 999M 999M` - surely you meant `memory_limit 999M` – d_inevitable Apr 03 '12 at 20:33
  • isn't your WordPress installation setting its own memory limit via `ini_set('memory_limit', ...)` ? – kuba Apr 03 '12 at 20:35
  • 1
    how about optimising the script, you shouldn't need that much memory. –  Apr 03 '12 at 20:36
  • Yeah I did edit the correct php.ini, it shows fine in phpinfo – Darrell Ding Apr 03 '12 at 20:37
  • @d_inevitable Yeah that was the output from phpinfo in php.ini its set to memory_limit 999M – Darrell Ding Apr 03 '12 at 20:38
  • @Dagon That's not an option, its wordpress, I can't optimize it since I have truckload of post metas used. – Darrell Ding Apr 03 '12 at 20:39
  • that's just a poor excuse for writing bad code. –  Apr 03 '12 at 20:40
  • I don't know what version of php your using, but prior to PHP 5.2.1, in order to use this directive it had to be enabled at compile time by using --enable-memory-limit in the configure line. (From the php manual http://www.php.net/manual/en/ini.core.php#ini.memory-limit) – ArendE Apr 03 '12 at 20:45
  • Is this VPS or shared host? If so perhaps that is the physical limit or the upper limit set by your provider? – d_inevitable Apr 03 '12 at 20:54
  • I did not see if you were running php-fpm. But if you are/were then you should check your fpm pool to see if it is set there. I ran into this where the pool file had `php_admin_value[memory_limit]=32M` – john Jun 13 '17 at 09:56

7 Answers7

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.

Barry Kooij
  • 400
  • 3
  • 12
4

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

Afron Orana
  • 625
  • 5
  • 14
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/

ArendE
  • 957
  • 1
  • 8
  • 14
  • 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 – Darrell Ding Apr 03 '12 at 20:45
  • Because it can be overruled by wordpress in the wp-config.php file. – ArendE Apr 03 '12 at 20:47
  • By using `define('WP_MEMORY_LIMIT', '64M');` in that file for example. – ArendE Apr 03 '12 at 20:49
  • Its not, already has both ini_set('memory_limit', '999M'); define('WP_MEMORY_LIMIT', '999M'); defined inside wp-config.php – Darrell Ding Apr 03 '12 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 http://stackoverflow.com/questions/3903363/allowed-memory-size-of-268435456-bytes-exhausted maybe it could be of some use :) – ArendE Apr 03 '12 at 21:02
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
Matthew Blancarte
  • 8,251
  • 2
  • 25
  • 34
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.

craniumonempty
  • 3,525
  • 2
  • 20
  • 18
  • 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 – Darrell Ding Apr 03 '12 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. – craniumonempty Apr 03 '12 at 21:09
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.

dAm2K
  • 9,923
  • 5
  • 44
  • 47
  • The parameter is acquired, just doesn't work in wordpress, there isn't any overrides, did a grep with for ini_set and nada – Darrell Ding Apr 03 '12 at 21:16
  • @DarrellDing you should grep php_value if you want to see if it's set in apache somewhere as well. – craniumonempty Apr 03 '12 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 03 '12 at 21:36
  • 2
    Fixed, it wasn't WP_MEMORY_LIMIT, apparently wordpress uses WP_MAX_MEMORY_LIMIT as their admin max limit. – Darrell Ding Apr 03 '12 at 21:40
  • 1
    Was the closest I got to an answer – Darrell Ding Apr 03 '12 at 22: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.
Benjamin Piette
  • 3,645
  • 1
  • 27
  • 24