Home  >  Article  >  Backend Development  >  Why Does PHP's Memory Limit Differ Between CLI and Webserver?

Why Does PHP's Memory Limit Differ Between CLI and Webserver?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-07 06:12:02473browse

Why Does PHP's Memory Limit Differ Between CLI and Webserver?

Resolving "Allowed Memory Size of X Bytes Exhausted" Error

While investigating the error message "Fatal error: Allowed memory size of 67108864 bytes exhausted," one may notice a discrepancy between the memory limit reported by PHPEcho and the actual available memory. This is because PHP's configuration can be set in various locations, including:

  • System-wide php.ini file
  • Apache configuration files (.conf)
  • CLI or CGI-specific php.ini file
  • Local .htaccess files
  • In-script (via ini_set())

In PHPInfo's output, the "Master" displayed value represents the default compiled memory limit, while the "Local" value reflects the actual active memory limit. This can be overridden in any of the aforementioned locations.

Furthermore, PHP differentiates between command-line and webserver-based operations. Running phpinfo() from the command-line may produce different memory limit values than when executed within a web-based script.

To resolve the memory exhaustion error, identify and modify the conflicting memory limit settings in the applicable configuration file(s) or PHP script(s). This can be determined by using the php -i | grep memory_limit command to display the CLI configuration.

The above is the detailed content of Why Does PHP's Memory Limit Differ Between CLI and Webserver?. 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