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).
Optimize your database: our problem went away after I optimized my database. That may or may not work for you. You can optimize your database using a plugin or by logging into phpMyAdmin.
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.