Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 264
Igor Yavych Avatar asked Apr 13 '13 20:04

Igor Yavych


2 Answers

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
like image 174
periklis Avatar answered Sep 30 '22 17:09

periklis


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');
like image 29
Glitch Desire Avatar answered Sep 30 '22 15:09

Glitch Desire