Home >Backend Development >PHP Tutorial >Why is My PHP Script Showing 'Allowed Memory Size Exhausted' When phpinfo() Shows a Higher Limit?

Why is My PHP Script Showing 'Allowed Memory Size Exhausted' When phpinfo() Shows a Higher Limit?

Susan Sarandon
Susan SarandonOriginal
2024-11-06 22:36:02571browse

Why is My PHP Script Showing

Investigating "Allowed Memory Size Exhausted" Error

The error message "Allowed memory size of X bytes exhausted" indicates that PHP has attempted to allocate more memory than allowed. While PHPInfo suggests a memory limit of 128M, the error suggests a limit of only 64M. To investigate this discrepancy, it's important to understand PHP's configuration hierarchy.

PHP's configuration can be set in multiple locations:

  • Master system php.ini (usually in /etc)
  • Apache's configuration (httpd.conf or .conf files)
  • CLI & CGI php.ini (use 'php -i | grep memory_limit')
  • Local .htaccess files
  • In-script (via ini_set())

In PHPInfo output, the "Master" value is the default and the "Local" value is what's in effect. The Local value may be overridden in any of the other locations.

Note that PHP has separate .ini files for command-line and webserver-based operation. Checking phpinfo() from the command line will show different values than from a web-based script.

In this case, the error is likely caused by an ini_set call in a primary PHP file. This call may have been added inadvertently and is overriding the global memory limit setting. To resolve the issue, locate the ini_set call and remove or modify it to ensure that it fits within the desired memory limit.

The above is the detailed content of Why is My PHP Script Showing 'Allowed Memory Size Exhausted' When phpinfo() Shows a Higher Limit?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn