Igor Yavych
Igor Yavych

Reputation: 4228

Fatal error: Out of memory when adding post in WP

I'm getting this nasty error Fatal error: Out of memory (allocated 18087936) (tried to allocate 77824 bytes). Weird thing is, it's 17,25 mb (allocated) and it tried to allocate 76 kb. Memory limit is 128MB, and as you can see it's not even close to that. VPS got ~400mb of free ram at that moment. It only happens when I'm posting something and not all the time. I find it weird and don't really know what can cause it. Let me know if you need any additional info.

Upvotes: 10

Views: 6821

Answers (9)

Chris
Chris

Reputation: 46

Given that your phpinfo() script returns the correct value for memory usage, this is obviously being set in Wordpress somewhere, and is therefore overriding the Apache provided values, so using a .htaccess to apply this still won't work.
This link (http://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP) suggests that Wordpress does its own memory management by default, so setting the ('WP_MEMORY_LIMIT', '256M') in the wp-config.php is logical.

If you have shell access to the server hosting your site I would suggest going to the DocumentRoot of your wordpress install and running the following commands:

grep -R "18M" *
grep -R -e '(WP_MAX_MEMORY_LIMIT|WP_MEMORY_LIMIT)' *

This will search through your files for the string 18M (the value your memory limit seems to be set to in human readable terms) and the configuration options for the Wordpress defined memory limit. I suspect that one of these commands will return positive output. You should then change the WP_MEMORY_LIMIT as suggested (although 256M may be a little high - try 64M initially, you don't want to cause yourself potential problems).

Upvotes: 1

Hiren Pandya
Hiren Pandya

Reputation: 980

Got it from this http://wordpress.org/support/topic/fatal-error-out-of-memory-messages?replies=24#post-1929111, thought I'd share it with you guys :


THIS TO BE ENTERED IN THE WP-CONFIG FILE WHICH IS IN THE ROOT OF THE WORDPRESS SETUP: ENTER AFTER : 
define('ABSPATH', dirname(__FILE__).'/'); THE FOLLOWING:

define('WP_MEMORY_LIMIT', '64M');

ALSO CREATE A PHP.INI WHICH SHOULD BE UPLOADED TO THE PLUGIN FOLDER IN WP-CONTENT:

 `memory_limit = 128M; //Maximum amount of memory a script may consume (64MB)
`

max_execution_time = 45;


upload_max_filesize = 15M;


post_max_size = 30M;

Hope this helps!

Upvotes: 2

Glitch Desire
Glitch Desire

Reputation: 15043

Hope this helps, as I had the same issue:

You're running into a limitation in WordPress's own memory limit, not your PHP memory_limit. Wordpress implemented this limit in order to prevent poorly written scripts from shutting down your whole PHP interpreter. Unfortunately, as you've noticed, it's rather barebones.

The easiest way I've found to fix this is to install the Change Memory Limit plugin from Wordpress plugin repository. It allows you to fix the issue without modifying any WP files manually.

The 64M default for the plugin will probably be fine for you.

Alternatively, if you don't want to trust a third party plugin, add the following line to wp-config.php:

define('WP_MEMORY_LIMIT', '64M');

Upvotes: 2

duellsy
duellsy

Reputation: 8585

It looks as through somewhere in the site, the memory limit is being overwritten, do a site wide search in the code for ini_set('memory_limit' and see what is returned.

Upvotes: 1

aakash
aakash

Reputation: 376

Add define('WP_MEMORY_LIMIT', '256M'); in your wp-config.php file. Its the easiest way.

Upvotes: 1

TECH N
TECH N

Reputation: 11

I install wp-memory-usage plugin by alexrabe on all my Wordpress sites.

This plugin helps you to see what Wordpress is seeing in terms of your PHP memory usage. Other approaches may show you the PHP settings at the server, however these settings are often overridden with various techniques the closer you get to a rendered page within the browser.

To set your max memory -> open your favorite text editor and create a file called php.ini; include in the file the following line:

memory_limit = 256M

Place a copy of the php.ini your Wordpress root directory. I also place copies in: /wp-admin; /wp-content; and /wp-includes.

Upvotes: 1

Volkan
Volkan

Reputation: 2210

I am not sure this causes the error, but it is worth checking for.

Many of the most untraceable pathetic out of memory errors are caused by :

1) User defined exception handlers, causing exceptions therefore recursing.

2) The above + trying to fetch class information of object originating the exception, and the class information testing causes an autoload attempt, in which autoload throws another exception and therefore recursing.

Have you done something conflicting with WP error handling or autoload?

Upvotes: 1

Ron van der Heijden
Ron van der Heijden

Reputation: 15080

Just an option that helped me debugging these errors.

If you have access to the .htaccess, you could try this:

php_value upload_max_filesize 128M
php_value post_max_size 128M
php_value max_execution_time 300
php_value max_input_time 300

If that doesn't help, you could try this to check the settings:

echo 'Max upload size: ' . ini_get('upload_max_filesize') . '<br />';
echo 'Max post size: ' . ini_get('post_max_size') . '<br />';
echo 'Memory limit: ' . ini_get('memory_limit');

I hope this works, for me it did.

Upvotes: 1

periklis
periklis

Reputation: 10188

The error says that the memory limit is 18M and not 128M. This means that somewhere the memory_limit is set to something different than 128M (local php.ini, or the application itself, since PHP can override this setting at run-time).

I would suggest that you first create a file called (say) phpinfo.php with the following contents:

<?php
phpinfo();
?>

and place it where your script runs. Then access the file with your browser and look for the actual memory_limit value. If it's still showing 128M both for "global" and "local" value, then probably somewhere in your code, there's a "ini_set("memory_limit", $value);" call or something similar. Otherwise, if it says 18M, look for other places where this can be set:

  • Check your wp-config.php file
  • Check for any local php.ini file (look into the phpinfo.php page to see the location of the actual loaded php.ini file)
  • Check for any .htaccess files that contain such a directive

Upvotes: 6

Related Questions