已用完 X 字节的允许内存大小

致命错误:允许的内存大小为 67108864 字节已用完(尝试分配 13965430 字节)

Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 13965430 bytes)

PHPInfo 显示我的 memory_limit 为 128M,所以我很困惑为什么错误说我只有 64M.phpinfo 有没有可能报错?还是让PHP使用两个独立的php.inis?

PHPInfo shows that I have a memory_limit of 128M, so I'm confused as to why the error says I only have 64M. Is it possible for phpinfo to report incorrectly? Or for PHP to use two separate php.inis?

该错误是由我的一位同事在我不知情的情况下添加的主要 php 文件之一中的 ini_set 调用引起的.

The error was being caused by an ini_set call in one of the primary php files that a co-worker of mine added without my knowledge.

推荐答案

PHP 的配置可以多处设置:

PHP's config can be set in multiple places:

  1. 主系统php.ini(通常在/etc某处)
  2. Apache 配置中的某处(httpd.conf 或每个站点的 .conf 文件,通过 php_value)
  3. CLI &CGI 可以有不同的 php.ini(使用命令 php -i | grep memory_limit 检查 CLI 配置)
  4. 本地 .htaccess 文件(还有 php_value)
  5. 脚本内(通过ini_set())
  1. master system php.ini (usually in /etc somewhere)
  2. somewhere in Apache's configuration (httpd.conf or a per-site .conf file, via php_value)
  3. CLI & CGI can have a different php.ini (use the command php -i | grep memory_limit to check the CLI conf)
  4. local .htaccess files (also php_value)
  5. in-script (via ini_set())

在 PHPinfo 的输出中,Master"值是编译后的默认值,Local"值是实际生效的值.它可以与默认值保持不变,也可以在上述任何位置被覆盖.

In PHPinfo's output, the "Master" value is the compiled-in default value, and the "Local" value is what's actually in effect. It can be either unchanged from the default, or overridden in any of the above locations.

另请注意,PHP 通常具有不同的 .ini 文件用于命令行和基于网络服务器的操作.从命令行检查 phpinfo() 将报告与在基于 Web 的脚本中运行它不同的值.

Also note that PHP generally has different .ini files for command-line and webserver-based operation. Checking phpinfo() from the command line will report different values than if you'd run it in a web-based script.

相关文章