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

Susan Sarandon
Release: 2024-11-06 22:36:02
Original
457 people have browsed it

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!