PHP:设置 memory_limits > 1024M 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9276212/
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
PHP : settings memory_limits > 1024M does not work
提问by Cédric Girard
For bads reasons I need to set memory_limits higher than 1G for a directory, but on my PHP 5.2.17 on Lenny server when I put for example 2048M I get only the php.ini default value (256M).
由于不好的原因,我需要为目录设置高于 1G 的 memory_limits,但是在 Lenny 服务器上的 PHP 5.2.17 上,当我放置例如 2048M 时,我只得到 php.ini 默认值 (256M)。
PHP run as an apache module, phpinfo give us (for the directory)
PHP 作为 apache 模块运行,phpinfo 给我们(用于目录)
memory_limit 1024M 256M
suhosin.memory_limit 0 0
Is there a limitation due to apache module, or PHP conf? I know the server only have 4G of RAM, it's just a special script.
是否有由于 apache 模块或 PHP conf 的限制?我知道服务器只有 4G 的内存,这只是一个特殊的脚本。
回答by kingmaple
How are you trying to set the memory limit? phpinfo() shows current PHP reserved memory limit, this is what is available due to php.ini having that set as a memory limit
你是如何尝试设置内存限制的?phpinfo() 显示当前的 PHP 保留内存限制,这是由于 php.ini 将其设置为内存限制而可用的
Writing this to Apache .htaccess in your script directory might work, if your server supports setting PHP commands through .htaccess:
如果您的服务器支持通过 .htaccess 设置 PHP 命令,则将其写入脚本目录中的 Apache .htaccess 可能会起作用:
php_value memory_limit 2048M
Since it may be possible that .htaccess commands for setting PHP values are turned off. Then you can also try this from PHP code:
因为用于设置 PHP 值的 .htaccess 命令可能被关闭。然后你也可以从 PHP 代码中尝试这个:
ini_set('memory_limit', '2048M');
If this doesn't work and .htaccess also doesn't work, then you need to contact server administrators.
如果这不起作用并且 .htaccess 也不起作用,那么您需要联系服务器管理员。
回答by nxasdf
I had this same issue where I needed my PHP script to use 4 GBs of RAM. The reason doesn't matter. The goal was to set a 4 GB limit in PHP.
我遇到了同样的问题,我需要我的 PHP 脚本来使用 4 GB 的 RAM。原因无所谓。目标是在 PHP 中设置 4 GB 的限制。
The initial idea was to use ini_set('memory_limit', '4096M');
but I found that this didn't work. I have no idea how or why to be honest, but that wasn't important to me at the time. I'm on a system with 32 GBs of RAM, it has to be possible.
最初的想法是使用,ini_set('memory_limit', '4096M');
但我发现这不起作用。我不知道如何或为什么要诚实,但这在当时对我来说并不重要。我在一个有 32 GB 内存的系统上,它必须是可能的。
I found that setting a limit 1 MB less acually worked, it's a solution that worked for me.
我发现将限制设置为 1 MB 的实际工作量减少了,这是一个对我有用的解决方案。
ini_set('memory_limit', '4095M'); // 4 GBs minus 1 MB
Edit Nov '16: Actually, I've never really played with it before but I've noticed on my system that this value seems to completely remove all memory limits for me. I'm able to use as much RAM as my system possibly provides.
16 年 11 月编辑:实际上,我以前从未真正玩过它,但我在我的系统上注意到这个值似乎完全消除了我的所有内存限制。我可以使用我的系统可能提供的尽可能多的 RAM。
回答by pollux1er
ini_set("memory_limit",-1);
This should normally remove limits
这通常应该删除限制
回答by Vincent Touzet
As describe here : http://www.hardened-php.net/suhosin/configuration.html#suhosin.memory_limit
如此处所述:http: //www.hardened-php.net/suhosin/configuration.html#suhosin.memory_limit
Suhosin will not let you set a value greater than the one the script started with.
Suhosin 不会让您设置的值大于脚本开头的值。
If you set the suhosin.memory_limitto 2048Mthen you'll be able to increase your memory usage.
如果您将suhosin.memory_limit设置为2048M,那么您将能够增加内存使用量。
回答by Stefano Turinetti
The limit of
的限制
ini_set('memory_limit', '4095M'); // 4 GBs minus 1 MB
is related to Operating System, with 32bit OS you must to use this maximum limit.
与操作系统有关,对于 32 位操作系统,您必须使用此最大限制。
I resolved an issue memory_limit today using this workaround.
我今天使用此解决方法解决了 memory_limit 问题。
Using a higher limit PHP have strange behaviour, it returns exhausted memory in some public non static method class when class was instanced, but putting a die() in the __construct method (to test the problem)
使用更高的限制 PHP 有奇怪的行为,当类被实例化时,它在一些公共非静态方法类中返回耗尽的内存,但在 __construct 方法中放置了一个 die()(以测试问题)