Skip to content

Resolving the 'Allowed memory size exhausted' PHP error message

When running PHP applications such as WordPress, Drupal, or custom scripts, you may encounter the error:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 33554432 bytes) in /home/example/public_html/filename.php on line 1622

This indicates that your script has used more memory than PHP is allowed to allocate.

  • The application consumes more memory than the default PHP limit.
  • Large plugins, themes, or modules require additional resources.
  • Inefficient code that does not release memory properly.
  • Heavy database queries or large file processing.
  • Use unset() to destroy variables and objects no longer needed.
  • Avoid loading large datasets into memory at once.
  • Break tasks into smaller chunks.

The method depends on your hosting environment:

Add or edit:

memory_limit = 256M

Add:

php_value memory_limit 256M

Add:

memory_limit = 256M
  1. Log in to cPanel.
  2. Go to Software → Select PHP Version.
  3. Click Switch to PHP Options.
  4. Locate memory_limit and increase the value.
  5. Save changes.
  • Disable unnecessary plugins or modules.
  • Update outdated extensions.
  • Use lightweight alternatives when possible.
  • Use cPanel’s resource usage tools to track memory consumption.
  • Identify scripts or plugins causing spikes.