PHP Memory Limit Error

Allowed Memory Size Exhausted Errors

Fatal error: Allowed memory size of 12582912 bytes exhausted (tried to allocate 23456789 bytes) in somefile.php
Fatal Error: PHP Allowed Memory Size Exhausted

These errors occur when PHP tries to process a large database record, or when importing or exporting a database.

To fix the problem, please modify the memory_limit line in php.ini to match this example:

memory_limit = 256M

We do set the maximum memory limit at 256 MB (268,435,456 bytes).

If you want to go higher, you will need a VPS plan or dedicated server.

So, if you see "Allowed memory size of 268435456 bytes exhausted..." in the error, then you cannot increase the limit any higher without a VPS plan or dedicated server. Dedicated Server and VPS customers with WHM access can change the limit by going to WHM > Service Configuration > PHP Configuration Editor.


Out of Memory Error

Fatal error: Out of memory (allocated 268435456) (tried to allocate 47 bytes) in somefile.php

If you see less than 268435456 bytes total allocated and being allocated, but still get an error like the example above, then we suggest you contact HostGator support to get assistance and advice.


Need help?

If you need assistance with correcting this error, please feel free to contact us, and we will be happy to help you.

Information for Employees:

PHP memory_limit can now be changed to up to 256 MB.

Please note that most times when a customer reaches the php memory_limit on their script, it will show allocation less than the full 256MB and usually ends up hitting the apache RLimitMem variable we have set in Apache. At times, the script itself can be stuck somewhere dealing with a lot of data that can't be processed efficiently. This applies to our shared/reseller servers and occasionally a VPS/Dedi when they have RLimits usually set under /usr/local/apache/conf/httpd.conf or /usr/local/apache/conf/includes/pre_main_global.conf.

Fatal error: Out of memory (allocated 168435456) (tried to allocate 47 bytes) in /home/toolsupp/public_html/classes/MySQL.php on line 154

Information for Chat Techs

Please contact a Jr. Admin L2 for assistance in updating the PHP memory_limit value.

If additional investigation is needed, such as modifying the RLimitMem variable, please escalate the request to a ticket.

Information for Admins

Please do not be hesitant to temporarily override this limit in a vhost include file for the affected domain during troubleshooting. This will save a ticket from getting multiple replies without a resolution. You will just need to remember to always remove this override when you have completed whatever needs to be done. On a shared or reseller server, _NEVER_ touch the pre_main_global.conf file.

(One perfect example of this would be through ticket ADQ-15955316. A Google base feed needed to be generated and seeing how this usually pulls a lot of resources to complete, we went ahead and just override the rlimit & php.ini memory_limit, ran the script to generate a feed, then reversed the changes. This customer will require a VPS/Dedi to run the feed on their own without intervention as we must maintain a stable environment for all users.)

How To Override vHost Limitations

Now, the steps to overriding this is somewhat simple. Follow the below for future reference in case you run into a ticket with the same issue. I'll use the site in the ticket above as an example scenario.

  1. Lookup the vhost include path for the site in question. http and https have different paths so view httpd.conf if you need a general idea on which to use as there are various options. This should be the same format on all cPanel boxes that are on apache2 which you can understand with the structure below.

    Affected URL - https://www.toolsupplycenter.com/
    SSL VHost Include Path (https) - /usr/local/apache/conf/userdata/ssl/2/toolsupp/toolsupplycenter.com/*.conf
    Regular Vhost Include Path (http) - /usr/local/apache/conf/userdata/std/2/toolsupp/toolsupplycenter.com/*.conf
  2. Do mkdir -p /usr/local/apache/conf/userdata/ssl/2/toolsupp/toolsupplycenter.com/ so the directory is created with the parent directories. Since we're accessing https, the ssl include path is used.
  3. Create a configuration file with the below entry. This can simply be named rlimit.conf for identification purposes. The server is looking for anything with a .conf extension.

    *RLimitMEM 138412032 141557760*

    This increases the apache memory limit for the vhost from a default 100MB to a previously tested 132-135MB limit which should allow most php scripts to continue through the memory error.
  4. Run /scripts/ensure_vhost_includes --user=theirusername or /scripts/ensure_vhost_includes --domain=domain.com which will modify httpd.conf to load the configuration path created in step 2.
  5. Finish troubleshooting or running whatever process the customer's script is stuck on and remember to delete the rlimit.conf file when you are completely finished.

Now, instead of simply stating that we don't allow a customer to use over 256MB of memory in PHP, we can at least attempt to correct the issue, while at the same time specifying the upgrade needed or showing the problematic source of the errors.