What's Actually Happening

WordPress runs out of PHP memory. The site shows white screen or fatal error about memory limit.

The Error You'll See

bash
Fatal error: Allowed memory size of 41943040 bytes exhausted (tried to allocate 2048 bytes) in /var/www/html/wp-includes/plugin.php on line 123

Why This Happens

  1. 1.PHP memory limit too low
  2. 2.Memory-heavy plugins
  3. 3.Large media processing
  4. 4.Too many active plugins
  5. 5.Inefficient code

Step 1: Increase Memory Limit in wp-config.php

php
define('WP_MEMORY_LIMIT', '256M');
define('WP_MAX_MEMORY_LIMIT', '512M');

Step 2: Increase PHP Memory Limit

```ini ; In php.ini memory_limit = 256M

; Or in .htaccess php_value memory_limit 256M ```

Step 3: Check Current Memory Usage

php
<?php
echo memory_get_usage(true) / 1024 / 1024 . ' MB';
echo memory_get_peak_usage(true) / 1024 / 1024 . ' MB';
?>

Step 4: Disable Problem Plugins

```bash # Via FTP/SSH: cd /wp-content/plugins/ mv plugin-name plugin-name.disabled

# Or in database: UPDATE wp_options SET option_value = '' WHERE option_name = 'active_plugins'; ```

Step 5: Check Memory-Intensive Plugins

bash
# Query Monitor plugin shows memory usage
# Install Query Monitor to identify issues

Step 6: Optimize Database

bash
# Repair and optimize database
# Use WP-CLI:
wp db optimize
wp db repair

Step 7: Increase Server Resources

```bash # Check PHP memory php -i | grep memory_limit

# Check available memory free -m ```

Step 8: Enable Object Cache

php
// In wp-config.php
define('WP_REDIS_HOST', '127.0.0.1');
define('WP_REDIS_PORT', 6379');

Step 9: Clean Up Transients

sql
DELETE FROM wp_options WHERE option_name LIKE '_transient_%';
DELETE FROM wp_options WHERE option_name LIKE '_site_transient_%';

Step 10: Monitor Memory

php
// Add to functions.php for debugging
add_action('shutdown', function() {
    error_log('Memory usage: ' . memory_get_peak_usage(true) / 1024 / 1024 . 'MB');
});
  • [Fix WordPress White Screen](/articles/fix-wp-white-screen-of-death)
  • [Fix WordPress Database Error](/articles/fix-wp-database-connection-error)