Knowledge Base

'Allowed memory size exhausted' error message in PHP

This article describes how to resolve a problem that may occur when you run a PHP-based web application, such as WordPress or Drupal.

Problem

When you try to view a PHP-enabled page, you receive an error message that resembles the following (the exact values and paths vary):

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

Cause

This problem occurs when an application uses more memory than PHP allows.

Resolution

If you develop a site using your own PHP code, you can try to make your code more memory-efficient. For example, you can use the unset() function to destroy variables and objects that you no longer need, thereby freeing up memory.

However, if you are running a third-party web application, such as WordPress or Joomla, it is highly inadvisable to modify the code directly. In such scenarios, you may need to increase the PHP script memory limit. The method to do this depends on the type of hosting account you have.

To determine which of the following methods applies to your account, please see this article.
  • If your account uses php.ini files to change PHP settings, for information about how to change the script memory limit, please see this article.
  • If your account uses .htaccess files to change PHP settings, for information about how to change the script memory limit, please see this article.
  • If your account uses CageFS, follow these steps:
    1. Log in to cPanel.
      If you do not know how to log in to your cPanel account, please see this article.
    2. In the Software/Services section of the cPanel home screen, click Select PHP Version:

      cPanel - Select PHPVersion icon

    3. Click Switch to PHP Settings.
    4. Locate the memory_limit row, select the new value for the script memory limit, and then click Apply.
    5. Click Save to save the settings. The new PHP setting takes effect immediately.