Learn how to fix the “Allowed Memory Size of Bytes Exhausted” cPanel fatal error. Our cPanel Support team is here to help you with your questions and concerns.

How to Fix the “Allowed Memory Size of Bytes Exhausted” cPanel Fatal Error

One of our customers recently ran into the dreaded “Allowed memory size of bytes exhausted” error message. This common issue can bring the website or application to a halt if not resolved quickly.

How to Fix the “Allowed Memory Size of Bytes Exhausted” cPanel Fatal Error

Today, we will break down what this error means, why it happens, and how we can fix and prevent it.

This error occurs when a PHP script tries to use more memory than what’s allocated to it in the server’s configuration.

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 4096 bytes) in /path/to/file.php on line 123

Let’s break down this message:

  • Allowed memory size: The maximum memory PHP allows a script to use.
  • Bytes exhausted: How much memory has already been used.
  • Tried to allocate: The extra memory the script needed.
  • File and line number: Where the script ran into trouble.

An Overview:

Key Impacts of the Erros

  • The PHP script stops running..
  • The page may break or not load at all.
  • We risk data loss, performance issues, and user frustration.

Common Causes

  • The memory limit in `php.ini` is too low for the script’s needs.
  • Processing large files, images, or datasets can quickly eat up memory.
  • Each plugin uses memory. Too many plugins can push usage over the limit.
  • Scripts that don’t free memory or manage data well can leak memory and trigger this error.

If you’re facing similar unexpected issues in cPanel, like “A fatal error or timeout occurred while processing this directive” or “No digest data for RPM” error, the root cause may also stem from misconfigurations or resource limitations.

How to Fix the Error

1. Increase PHP Memory Limit

We can increase the PHP memory limit in 3 ways.

Edit `php.ini`

  1. First, open `php.ini`.
  2. Then, find or add this line:

    memory_limit = 256M

  3. Now, save and make it recursive if needed.

Modify `.htaccess`

  1. Open `.htaccess` in the root directory.
  2. Then, add:

    php_value memory_limit 256M

  3. Finally, save the file.

Use cPanel’s MultiPHP INI Editor

  1. Go to cPanel > Software > MultiPHP INI Editor.
  2. Then, select the domain.
  3. Change `memory_limit` to:

    memory_limit = 256M

  4. Finally, save the changes.

2. Deactivate Unused Plugins

  1. First, go to `/wp-content/` and rename the `plugins` folder to something like `plugins-bad`.
  2. Then, create a new empty `plugins` folder.
  3. Now, reload the site. If the error disappears, it’s plugin-related.
  4. Restore the original folder and activate plugins one by one to find the culprit.

3. Optimize the PHP Code

We can use `unset()` to clear large variables once they’re no longer needed:

unset($largeArray);

Remember to refactor the code to be more memory-efficient. Also, avoid loading unnecessary data into memory.

Additional Tips

Here are a few tips to prevent this error:

  • Monitor memory usage regularly.
  • Optimize scripts and avoid memory-heavy operations.
  • Limit plugins, especially in WordPress.
  • Keep backups before making major changes.

Also, errors like “NetworkManager is installed and running” or “RPMDB open failed” in cPanel can be tricky and related to system or package management conflicts.

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

Whether increasing memory limits or cleaning up code, a little tuning can prevent the “Allowed memory size exhausted” error.

In brief, our Support Experts demonstrated how to fix the “Allowed Memory Size of Bytes Exhausted” cPanel fatal error.

Similar Posts