PHP 将 memory_limit 增加到 128M 以上

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18140948/
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-25 17:03:13  来源:igfitidea点击:

PHP increase memory_limit above 128M

phpapachememory-limitsuhosinini-set

提问by user2554863

I have running a Debian Squeeze with Standard Apache and PHP, installed via aptitude.

我运行了一个带有标准 Apache 和 PHP 的 Debian Squeeze,通过 aptitude 安装。

No I try to run :

不,我尝试运行:

<?php
 echo ini_get("memory_limit")."\n";
 ini_set("memory_limit","1024M");
 echo ini_get("memory_limit")."\n";
?>

Result: 128M 128M

结果:128M 128M

What I have tried to change this behavior and some facts:

我试图改变这种行为和一些事实:

/etc/php5/apache2/php.ini:
safe_mode = Off
memory_limit = 128M

/etc/php5/apache2/conf.d/suhosin.ini:
[suhosin]
suhosin.memory_limit = 2048M

I can verify this settings with phpinfo();, after service apache2 restart.

我可以使用 phpinfo(); 验证此设置,在service apache2 restart.

Why I can not set the Memory Limit above 128M?

为什么我不能将内存限制设置为 128M 以上?

Note:

笔记:

<?php
 echo ini_get("memory_limit")."\n";
 ini_set("memory_limit","127M");
 echo ini_get("memory_limit")."\n";
?>

Result: 128M 127M

结果:128M 127M

Kind Regards

亲切的问候

回答by vee

Changing of memory_limitis blocked by suhosin extension.

memory_limitsuhosin 扩展阻止了更改。

From the docs at: http://www.hardened-php.net/suhosin/configuration.html#suhosin.memory_limit

来自以下文档:http: //www.hardened-php.net/suhosin/configuration.html#suhosin.memory_limit

suhosin.memory_limit

Type: Integer Default: 0 As long scripts are not running within safe_mode they are free to change the memory_limit to whatever value they want. Suhosin changes this fact and disallows setting the memory_limit to a value greater than the one the script started with, when this option is left at 0. A value greater than 0 means that Suhosin will disallows scripts setting the memory_limit to a value above this configured hard limit. This is for example usefull if you want to run the script normaly with a limit of 16M but image processing scripts may raise it to 20M.

suhosin.memory_limit

类型:整数 默认值:0 只要脚本不在安全模式下运行,它们就可以自由地将 memory_limit 更改为他们想要的任何值。Suhosin 改变了这一事实,并禁止将 memory_limit 设置为大于脚本开始时的值,当此选项保留为 0 时。大于 0 的值意味着 Suhosin 将禁止脚本将 memory_limit 设置为高于此配置硬的值限制。例如,如果您想以 16M 的限制正常运行脚本,但图像处理脚本可能会将其提高到 20M,这将非常有用。

So with suhosin extension enabled, you need to change it and restart apache.

因此,启用 suhosin 扩展后,您需要更改它并重新启动 apache。