php PHP内存限制

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/620602/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 23:17:09  来源:igfitidea点击:

PHP memory limit

php

提问by JW.

In PHP 5.0.4, if you don'tconfigure -enable-memory-limit, the memory_limit directive is ignored. (It's set to 8M in the recommended php.ini file, but the documentation says it's ignored.) So in that case, is there a per-script memory limit at all, or is it only limited by the system?

在 PHP 5.0.4 中,如果您没有配置 -enable-memory-limit,则 memory_limit 指令将被忽略。(在推荐的 php.ini 文件中它被设置为 8M,但文档说它被忽略了。)那么在这种情况下,是否存在每个脚本的内存限制,还是仅受系统限制?

I ask because I'm upgrading to PHP 5.2.8, and it doesallow memory limiting by default. So now I actually have to set the value to something appropriate. The recommended php.ini file now has it set to 128M, but I don't know if that's moreor lessthan what 5.0.4 did by default!

我问是因为我要升级到 PHP 5.2.8,并且默认情况下它确实允许内存限制。所以现在我实际上必须将值设置为适当的值。推荐的 php.ini 文件现在将其设置为 128M,但我不知道这是否比 5.0.4 的默认值还是

I'm upgrading production systems, so I'd like to avoid any major change in behavior. The documentation(search for "memory_limit") is very confusing on this point. It says "default", but I don't know if that means the default value set in the config file, or the default value that it uses when memory limiting is disabled.

我正在升级生产系统,所以我想避免行为上的任何重大变化。该文档(搜索“memory_limit的”)非常混乱这一点。它说“默认”,但我不知道这是否意味着在配置文件中设置的默认值,或者它在禁用内存限制时使用的默认值。

采纳答案by JW.

The memory limiter in PHP is optional; if you disable it at compile time there's no limit at all.

PHP 中的内存限制器是可选的;如果您在编译时禁用它,则根本没有限制。

In 5.0.4 it's disabled unless you explicitly asked for it at compile time, the reason being that the memory limiter was useless until 5.2and didn't count a lot of things it should have done, including things like the mysql functions. It's turned onfrom 5.2.1 now that they learned to count.

在 5.0.4 中它被禁用,除非您在编译时明确要求它,原因是内存限制器在5.2之前没有用,并且没有计算它应该完成的很多事情,包括像 mysql 函数这样的事情。它原来从5.2.1现在他们学会了算。

If in doubt, disable it or make sure you update the config file to use the new default. Leaving it at 8MB and upgrading to 5.2.8 will almost definitely cause problems.

如果有疑问,请禁用它或确保更新配置文件以使用新的默认值。将其保留为 8MB 并升级到 5.2.8 几乎肯定会导致问题。

回答by cletus

128M is very high. You may need that but I'd be surprised.

128M已经很高了。你可能需要那个,但我会很惊讶。

More to the point, the limit can be set to a global default in php.ini:

更重要的是,可以在 php.ini 中将限制设置为全局默认值:

memory_limit = 32M

You can also override it in scripts:

您还可以在脚本中覆盖它:

<?php
ini_set('memory_limit', '128M');
...

You'll probably find you only have a handful of scripts that need a lot of memory. Find some comfortable value (with testing) and then just up it for the ones that need more.

您可能会发现只有少数脚本需要大量内存。找到一些舒适的价值(通过测试),然后为需要更多的人增加价值。

回答by Byron Whitlock

The default memory limit in php before 5.2 was 8MB, it was increased to a default of 16MB in php 5.2.0. It is currently a default of 128MB.

php 5.2 之前的默认内存限制是 8MB,在 php 5.2.0 中增加到默认的 16MB。目前默认为 128MB。

To reproduce behavior of the pre 5.2 versions, explicitly set the memory limit to 8MB.

要重现 5.2 之前版本的行为,请将内存限制明确设置为 8MB。

Look under "Resource Limits" on the php.net website.

查看 php.net 网站上的“资源限制”。

http://us.php.net/ini.core

http://us.php.net/ini.core

EDIT

编辑

"Prior to PHP 5.2.1, in order to use this directive it had to be enabled at compile time by using -enable-memory-limit in the configure line. "

“在 PHP 5.2.1 之前,为了使用这个指令,它必须在编译时通过在配置行中使用 -enable-memory-limit 来启用。”

Check the compile flags of your old server, if you didn't have it enabled no limit was enforced.

检查旧服务器的编译标志,如果您没有启用它,则不会强制执行任何限制。