No articles found
Try different keywords or browse our categories
Fix: Allowed memory size exhausted in WordPress error - Quick Solution
Quick fix for 'Allowed memory size exhausted' error in WordPress. Learn how to increase PHP memory limit and optimize WordPress performance.
The ‘Allowed memory size exhausted’ error in WordPress occurs when PHP runs out of allocated memory while executing scripts. This typically happens with large operations like importing content, running plugins, or processing images.
How the Error Happens
❌ Error Scenario:
// ❌ This can cause memory exhaustion
// Fatal error: Allowed memory size of 33554432 bytes exhausted
// (tried to allocate 32 bytes) in /wp-includes/class-wp-object-cache.php
✅ Quick Fix - Increase Memory Limit
Solution 1: Update wp-config.php
// ✅ Add to wp-config.php file
// Increase WordPress memory limit
ini_set('memory_limit', '512M');
// Or define WordPress specific memory limit
define('WP_MEMORY_LIMIT', '512M');
define('WP_MAX_MEMORY_LIMIT', '512M');
Solution 2: Update php.ini
; ✅ Add to php.ini file
memory_limit = 512M
max_execution_time = 300
max_input_time = 300
upload_max_filesize = 64M
post_max_size = 64M
Solution 3: Update .htaccess
# ✅ Add to .htaccess file
php_value memory_limit 512M
php_value max_execution_time 300
php_value max_input_time 300
php_value upload_max_filesize 64M
php_value post_max_size 64M
Solution 4: WordPress Plugin Memory Fix
// ✅ Add to functions.php for plugin-specific memory
// Hook into plugin activation
add_action('plugins_loaded', function() {
if (is_admin()) {
ini_set('memory_limit', '256M');
}
});
Solution 5: Temporary Memory Increase for Specific Operations
// ✅ Increase memory for specific operations
function increase_memory_for_import() {
// ✅ Increase memory limit temporarily
ini_set('memory_limit', '512M');
ini_set('max_execution_time', 300);
}
// ✅ Hook to specific WordPress actions
add_action('import_start', 'increase_memory_for_import');
add_action('wp_import_posts', 'increase_memory_for_import'); Related Articles
Fix: Fatal error: Allowed memory size exhausted error in PHP
Learn how to fix the 'Fatal error: Allowed memory size exhausted' error in PHP. Complete guide with solutions, optimization techniques, and memory management best practices.
Fix: 502 Bad Gateway on PHP sites error and fix
Quick fix for 502 Bad Gateway error on PHP sites. Learn how to resolve server gateway issues and improve PHP application stability.
Fix: 429 Too Many Requests error
Quick fix for '429 Too Many Requests' error. Learn how to implement rate limiting and handle API rate limits effectively.