'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.

Table of Contents

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.
Get PHP Hosting

Article Details

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.