WordPress has been very good to us. We have never had major issues running it on all our servers. But once in a while things just don’t quite work. One of those times, we were getting this message every time we tried to post a new article or update existing ones: “Memory Issue: Fatal error: Allowed memory size of 268435456 bytes exhausted.” We are on a dedicated server with plenty of RAM and a powerful processor. The easiest way to handle this is to increase the memory limit. But if you have unoptimized code that cause memory leak and other issues, temporary fixes won’t do. Here are a few ways you can go about fixing issues like this:
Remove and track the performance of your plugins: the first thing I usually do when things go wrong is deactivate all plugins and keep testing. You could always use a plugin performance monitor to get a better idea which ones may be causing your site issues (e.g. similar post plugins).
Configure PHP using your WebHost Manager: this does not work for everyone. But on a dedicated server like ours, we could simply log into cPanel, go to PHP Configuration Editor, and change the memory limit.
Change your php.ini or .htaccess file: if you have access to this file on your server, you could just edit it and change the line ‘memory_limit’ to something you are comfortable with (e.g. memory_limit = 512M). Don’t have access to that file? This might work: php_value memory_limit 128M. You have to add it to your .htaccess file.
Define memory limit in your wp-config.php file: this approach is worth pursuing if you don’t have access to your php.ini or for some reason can’t edit your site’s .htaccess file. Just add this line to your configuration file: define(‘WP_MEMORY_LIMIT’, ‘512M’)
Keep in mind that your job is not done unless you figure out what is causing these issues. You have to check your plugins, server configurations, and anything else that could be responsible. Problems like this could come back to bite you where it hurts down the road unless you permanently fix them.