Help Docs Server Administration Linux Server Administration Troubleshooting — Memory Limit Error

Troubleshooting — Memory Limit Error

The PHP memory_limit sets a cap on memory use per script, preventing server crashes from scripts consuming excessive RAM.

When you run a PHP script on your server, it takes up a certain amount of memory while it is being executed. Using the PHP memory_limit directive will limit how much memory each script can use while it is running. If your server is not configured with a memory_limit, any single PHP script on the server could cause it to run out of RAM and crash with little to no evidence of what happened.

Memory Limit Error

When the memory_limit is reached, the script will be terminated and an error will show in your error_log. The error will look something like this:

PHP Fatal error: Allowed memory size of X bytes exhausted (tried to allocate X bytes) in /home/user/public_html/script.php on line X. referer http://domain.com/index.php?action=something

What does this error mean?

PHP Fatal error:

This means the error is fatal to the script being run. When it reached the memory limit, the script execution was terminated.

Allowed memory size of X bytes exhausted

This is the size of the memory_limit that was set for this script. While your RAM will be in Megabytes, the memory_limit is measured in bytes.

(tried to allocate X bytes)

This means the script tried to use additional memory that was not available.

/home/user/public_html/script.php on line X

Here you are shown the line of code in the script that tried to push past the memory limit. This helps for diagnostic purposes, but may not be the only line in the script which caused the memory limit to be reached.

referer http://domain.com/index.php?action=something

This section of the error will tell you which site the script was running on that caused the error. Knowing this information can be useful for recreating the issue for troubleshooting, but often the memory_limit is reached by modification of pages and not just by a user browsing.

How Do I Fix the Error?

The first step to troubleshooting memory_limit issues is to increase the limit for your server as a whole. This can be done with just a few clicks in WHM. If you aren’t sure which version your server is running, see how to locate it in our article What is EasyApache 4? Once you’ve determined that, please select one of the links below.

Setting PHP memory_limit with EasyApache 4

Notice:

EasyApache 3 is scheduled for deprecation/end of life in December 2018. It is recommended that all servers upgrade to EasyApache 4. For more information on the deprecation schedule for EasyApache 3, check out the cPanel Blog. If you have not yet upgraded, please contact our Support team to schedule an upgrade.
Was this article helpful?