A PHP "Allowed Memory Size Exhausted" error occurs when a script attempts to use more memory than the maximum limit allowed by your PHP configuration. This typically results in a blank page or a specific error message, and it is common when processing large amounts of data, high-resolution images, or complex database queries.
Before you begin
You will need:
Access to your website's control panel (such as cPanel or Windows Control Panel)
The specific URL where the error is occurring
Knowledge of the specific script or plugin causing the issue (if known)
Check the source of the error
To resolve the issue, you must first determine if the error is caused by a specific script, a plugin, or a theme.
Identify the URL where the error appears.
Attempt to access the page. If the error only appears on a specific page (such as a search results page or a media upload page), the issue is likely tied to a specific plugin or script.
If the error appears across the entire site, it may be caused by a global configuration issue or a core system conflict.
Identify the specific script or plugin
If the error is localized to a specific area of your site, you can isolate the cause:
If using a CMS like WordPress, temporarily deactivate the plugins associated with the page that is failing.
Refresh the page.
If the page loads correctly, the last active plugin is the cause.
If the page still fails, switch to a default theme. If the page loads, the issue is within your current theme's code.
Increase the PHP memory limit
If the script requires more memory to function correctly, you can increase the limit in your hosting environment.
Using your control panel
Log in to your control panel (cPanel or Windows Control Panel).
Locate the Select PHP Version or PHP Selector icon.
Select Options or Editor.
Find the
memory_limitsetting.Change the value to a higher limit (e.g.,
256Mor512M).Save the changes.
Using a .user.ini or php.ini file
If you cannot change the setting via the control panel, you can create a configuration file in your website's root directory.
Create a new file named
.user.ini(or edit the existingphp.iniif available).Add the following line to the file:
memory_limit = 256MSave the file and refresh your website.
Note: The specific value you choose depends on your hosting plan's maximum allowed limits. Consult your account details if you are unsure of the maximum allowed value.
Confirm the result
The "Allowed Memory Size Exhausted" error message no longer appears on the affected page.
The page loads successfully, even when performing the action that previously triggered the error.
If the error persists after increasing the limit
If the error remains after increasing the memory_limit, the script may have a coding inefficiency, such as an infinite loop or an extremely unoptimized database query.
Check the PHP error logs in your control panel to see the specific file and line number where the error occurs.
If the error occurs at a specific line in a plugin or theme file, contact the developer of that specific software.
If the error occurs in a custom script, contact a developer to optimize the code.
Limitations
Increasing the memory limit does not fix underlying code issues. If a script is poorly written, it may continue to consume excessive memory regardless of the limit set. Additionally, some hosting environments may have a hard cap on the maximum memory allowed per script.
