Hostxpeed
Login Get Started →
Troubleshooting

Fix PHP "Memory Exhausted"

4 min read
28 views
Jun 10, 2026

Understanding the Error

Fatal error: Allowed memory size of 134217728 bytes exhausted

PHP script exceeded memory_limit in php.ini.

Fix 1: Increase Memory Limit

Edit php.ini:

# Find php.ini location
php -i | grep "Loaded Configuration File"

# Update memory_limit
memory_limit = 256M

# Restart PHP-FPM
sudo systemctl restart php*-fpm

Fix 2: Per-Directory Increase (.htaccess)

php_value memory_limit 256M

Fix 3: In Script (Temporary)

ini_set('memory_limit', '256M');

WordPress Memory Fix

Add to wp-config.php:

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

Find Memory Leak

Debug which code uses memory:

// Add to script
echo memory_get_usage() . "\n";
echo memory_get_peak_usage() . "\n";

Common causes:

  • Loading huge datasets without pagination
  • Infinite loops
  • Unoptimized WordPress plugins

⚠️ Don't set memory_limit higher than available server RAM.

Was this article helpful?