In this guide, you may see the 4 methods to increase the memory limit for WordPress and WooCommerce. You can see, for example, how to define wp_memory_limit in the wp config php file to raise the memory limit. Issues with low memory can slow down a site or even break it.
Contents
How does an error message about WordPress memory limit look like?
Sometimes, you may encounter the following notice (in the system logs or the browser):
Fatal error: Allowed memory size of 12345678 bytes exhausted (tried to allocate 2345678 bytes) in /home/your-username/public_html/wp-includes/plugin.php on line 1000
This error message informs you about the memory limit and tells you how many bytes it was exceeded. There is also a filepath to a file that caused the error and the specific number of a line inside that file. If none of the below methods won't work, then this info can be useful then reporting the error to the plugin developer.
Another version of that error message:
Fatal error: Out of memory (allocated 12345678) (tried to allocate 2345678bytes) in /home/your-username/public_html/wp-includes/plugin.php on line 1000
Both messages tell you that there is no memory left for PHP scripts. It is caused by the server's limit and in most cases changing the server's configuration will solve this issue. However, sometimes the server's configuration cannot be changed or the allowed memory limit is very low.
How to increase the WordPress memory limit?
By default, WordPress will attempt to increase the memory allocated to PHP to 40MB for a single site and 64MB for a multisite. If you experience an error shown above, it means that these values are too low. What is the required memory limit? It depends on the plugins you are using. 128 MB is usually enough, but for some plugins, it may be too low.
You can check your memory limit in the WooCommerce System Status (in your WordPress admin panel: WooCommerce > Status).
In some cases, the value displayed in the System Status might not be correct. If the server has a higher limit than the one set for WordPress, then in the Status there will be shown a maximum value for WordPress. The value can also be incorrect if the limit set in wp-config.php is higher than the one in the server settings.
The WordPress system status may help in troubleshooting the issue with plugins consuming the memory and cpu limits.
Method 1: Edit php.ini file
You need access to the php.ini file on the server/hosting. It's possible to add the file if there isn't one inside the WordPress installation folder.
Then, you may set the memory limit by changing this line. If your line shows 64M try 128M:
memory_limit = 128M
M stands for Megabytes.
Method 2: Edit .htaccess file
If you don’t have access to php.ini or the above method has failed, please try adding this to an .htaccess file:
php_value memory_limit 128M
.htaccess file is located in the root directory of your WordPress installation.
Method 3: Edit wp-config.php file
Add this to the top of the file, before the line that says, “Happy Blogging” to raise the wp memory limit:
define('WP_MEMORY_LIMIT', '128M');
wp-config.php file is located in the root directory of your WordPress installation.
Method 4: Change your PHP version
It may happen that the solutions listed above will fail.
Hosting providers sometimes do not allow editing the memory limit or the limit is too low. In this case, you should contact your provider and ask him to set a higher memory limit. If the limit won't be high enough, you should change your hosting plan or choose a different hosting provider.
However, there may be also another way of solving this issue. You can change your PHP version to a higher version in the hosting user panel. New PHP versions are more efficient and often use less memory. If you can, you may change your PHP version to 7.2 or higher. You may read more on how to switch the PHP version for WordPress.
WordPress memory limit: why does it matter?
Running out of memory for executing scripts and WordPress processes can influence WordPress sites directly. For example:
- some processes may not be finished,
- WordPress and plugins will not work properly,
- users will not see the results of the action taken,
- a site may freeze,
- a browser can show a white screen or error message, etc.
What's more, all of these effects are jeopardizing UX and normal functions on a WordPress site.
Most frequent reasons for memory limit problem
Now, let's have a look at some common causes of the memory limit:
- Too many plugins and scripts running simultaneously on a WordPress site
- Older plugin versions (not updated)
- Server limits and PHP version
- Server isn't working
- Hosting limits and no option for temporary memory spikes
- High traffic
- Plugins and themes consuming memory
- No caching
- A lot of widgets on a site
- Dynamically generated content
- A lot of media files, scripts, fonts, or external content on a page
- Multiple queries to/ from the WordPress database
- Complex scripts
How to handle the WP memory limit? Checklist
First, the above reasons for the memory limit problem can be addressed. You may use the checklist below to run the audit/ scan so you find the cause(s), define things to repair, increase WordPress memory limit, or ask for help:
- Low memory limit. Try to increase the memory limit for WordPress using 4 methods. But you may try to find out what caused the issue and be aware of memory usage anyway.
- When changing the PHP version remember about compatibility with plugins and themes.
- Check out if the software is up to date (plugins, themes, WordPress, WooCommerce).
- Consider updating plugins and themes (after doing a backup).
- Is it connected to higher traffic or using specific plugins (e.g. exporting data or bulk updating content).
- Limit the number of plugins by deactivating them temporarily.
- If the issue is critical, you may turn off some plugins by changing the folder name via FTP.
- Optimize the media.
- Lower the number of externally-loaded content or widgets.
- Enable caching.
- Find out if a site did not exceed the memory or cpu limits.
- See if the issue happens during a specific time of the day.
- After exceeding the certain memory amount (e.g. per month), the limits went down automatically.
- Can you increase the memory limit for WordPress or set dynamic memory allocation during such events?
- Does a memory spike occur in a particular place - check out WordPress logs.
- If the issue is plugin or theme related you may try to get the author's support.
- Contact hosting support to check the server logs, set appropriate limits, consult the issue, or find out about dynamic memory increase options.
- Optimize the memory allocation, and set the default memory limit.
Where to find help for wp_memory_limit or WordPress memory issues?
You can try handle the issue or:
- Contact a web developer or a software company that build a site,
- Delegate the issue to an IT department or hire a person,
- Contact the hosting provider if the issue can be fixed there,
- Consider dynamic memory limits during high traffic,
- Or think about upgrading the hosting PHP parameters or type (shared hosting to vpn).
You may also check out WP Desk Care - professional support for WordPress & WooCommerce.
You may check out WP Desk plugins 😊.