If you‘ve seen the dreaded "allowed memory size exhausted" error in WordPress, you‘re not alone. Out of memory errors have become increasingly common for modern WordPress sites.
As a WordPress professional with over 15 years of experience, I‘ve seen my fair share of clients running into this frustrating issue. But not to worry – with the right troubleshooting, increasing your PHP memory limit is an easy fix.
In this comprehensive guide, I‘ll draw upon my WordPress technical expertise to walk you through everything you need to know to resolve WordPress memory errors for good.
Contents
The Growing Memory Needs of WordPress Sites
WordPress uses the PHP programming language to dynamically generate and serve web pages. PHP scripts execute using a portion of your web server‘s memory.
The PHP memory limit determines how much memory a single PHP script (like WordPress) can use at once. The default is often only 32MB or 64MB – not enough for most modern WordPress sites.
Over the years, I‘ve seen the average memory needs of WordPress sites grow substantially:
Site Type | Typical Memory Limit |
---|---|
Simple blog | 64-128MB |
Small business site | 128-256MB |
Ecommerce site | 256-512MB |
Membership site | 512MB-1GB |
Why are WordPress sites needing more and more memory?
A few key reasons:
- Sites are loading more high resolution images, videos, and rich media. A single image can easily consume 16MB+ of memory.
- Plugins are becoming more robust. A site with 50+ plugins can generate major memory overhead.
- Traffic levels are increasing, putting strain on caching systems.
So don‘t feel bad if your site is exceeding the default memory limit – you‘re not alone! The good news is increasing the limit is a simple fix.
Behind the Scenes: How PHP Memory Works
Before we dive into solutions, let‘s briefly cover some technical basics on how WordPress utilizes PHP memory.
When a visitor requests a page on your site, WordPress…
- Loads the required PHP scripts into memory
- Assembles the page content like HTML, images, etc.
- Returns the fully assembled page to the user‘s browser.
If assembling the page exceeds the current memory limit, that‘s where you‘ll run into the exhaustion error.
Now let‘s talk about how we can expand that memory capacity…
3 Options to Increase Your PHP Memory Limit
Here are 3 common options for increasing the memory limit available to WordPress:
1. Increase via wp-config.php (Simplest)
The wp-config.php file located in your WordPress root folder controls some core WordPress settings. We can use it to directly set a higher memory limit:
define( ‘WP_MEMORY_LIMIT‘, ‘256M‘ );
This is the simplest approach that works for most sites. Just be sure to upload wp-config.php back to your WordPress root folder after saving changes.
Based on my experience, I‘d recommend 128-256M for small sites and up to 512M for sites with heavy plugins/traffic.
2. Increase via .htaccess (Intermediate)
The .htaccess file also allows tweaking PHP settings:
php_value memory_limit 256M
This method offers more granular control at the server level. However, some hosts block overriding PHP settings via .htaccess.
I‘ve found .htaccess edits work about 90% of the time – so it‘s worth trying if wp-config.php doesn‘t cut it.
3. Increase via php.ini (Advanced)
The php.ini file controls global PHP settings on your server. But editing it can be tricky:
- Requires server file system access most hosts don‘t provide.
- Can potentially impact other websites on your server.
- Easy to break things if you‘re unfamiliar with PHP configuration.
My advice is to avoid php.ini edits unless you‘re an expert. It‘s safer to request your host increase the limit at the user or account level.
But for completeness, here‘s what a php.ini change looks like:
memory_limit = 256M
So in summary, wp-config.php should be your first option, with .htaccess as a fallback. Leave php.ini as a last resort.
Finding the True Cause of High Memory Usage
Increasing the memory limit is a simple and effective solution. But it also pays to dig deeper – why is your WordPress site using so much memory in the first place?
A few common culprits I check when diagnosing high memory sites:
-
Bloated themes – Complicated themes like Avada can consume huge memory processing complex layouts and elements. Simplifying your theme is one optimization.
-
Too many plugins – Plugins load classes, make database queries, and initialize features. Too many active plugins can add overhead. Do an audit and remove any unnecessary plugins.
-
Images – Modern high resolution images require much more memory to process and resize. Optimize, lazy load or serve images through a CDN to reduce local image processing strain.
-
Traffic spikes – Caching systems like Redis can run out of memory on traffic spikes. Consider a distributed cache like Memcached that handles spikes better.
So while increasing PHP memory is the solution right now, consider if any optimizations could improve your site‘s overall resource efficiency.
Wrapping Up
Hopefully this guide provided you a comprehensive look at resolving WordPress memory errors from a technical expert‘s perspective. To recap:
- The default PHP memory limit is often insufficient for modern WordPress sites.
- Errors can be fixed by increasing the limit via wp-config.php or .htaccess.
- It‘s also wise to optimize your site and upgrade your hosting over time.
If you found this guide helpful, please share it with others who may be struggling with the same issue! I‘m happy to help the WordPress community with my many years of experience.