如何增加超过 2GB 的 PHP 内存限制?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11885191/
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
How to increase memory limit for PHP over 2GB?
提问by mikikg
I have an problem increasing memory limit for PHP as Apache module.
我在增加 PHP 作为 Apache 模块的内存限制时遇到问题。
If I put following directive in Apache configuration, that work OK:
如果我将以下指令放在 Apache 配置中,则可以正常工作:
php_value memory_limit 1.99G
But over 2GB do not work, it's restore this value back to 128MB.
但是超过 2GB 不起作用,它会将这个值恢复到 128MB。
What is the problem here? I need more memory for some PDF related tasks.
这里有什么问题?对于一些与 PDF 相关的任务,我需要更多内存。
Server is Debian 2.6.32-5-amd64 #1 SMP, PHP 5.3.3-7+squeeze13 with 12GB physical RAM.
服务器是 Debian 2.6.32-5-amd64 #1 SMP,PHP 5.3.3-7+squeeze13,12GB 物理内存。
采纳答案by Claudiu Claw
Have you tried using the value in MB ?
您是否尝试过使用 MB 中的值?
php_value memory_limit 2048M
Also try editing this valuein php.ininot Apache.
也尝试在非Apache 中编辑此值。php.ini
回答by Ray
I would suggest you are looking at the problem in the wrong light. The questtion should be 'what am i doing that needs 2G memory inside a apache process with Php via apache module and is this tool set best suited for the job?'
我建议您以错误的眼光看待问题。问题应该是“我在做什么需要通过 apache 模块使用 Php 的 apache 进程中的 2G 内存,这个工具集是否最适合这项工作?”
Yes you can strap a rocket onto a ford pinto, but it's probably not the right solution.
是的,您可以将火箭绑在福特 pinto 上,但这可能不是正确的解决方案。
Regardless, I'll provide the rocket if you really need it... you can add to the top of the script.
无论如何,如果你真的需要它,我会提供火箭......你可以添加到脚本的顶部。
ini_set('memory_limit','2048M');
This will set it for just the script. You will still need to tell apache to allow that much for a php script (I think).
这将仅为脚本设置它。您仍然需要告诉 apache 为 php 脚本允许那么多(我认为)。
回答by Indrajeet Singh
For unlimited memory limit set -1in memory_limitvariable:
对于-1在memory_limit变量中设置的无限内存限制:
ini_set('memory_limit', '-1');
回答by Timur
You should have 64-bit OS on hardware that supports 64-bit OS, 64-bit Apache version and the same for PHP. But this does not guarantee that functions that are work with PDF can use such big sizes of memory. You'd better not load the whole file into memory, split it into chunks or use file functions to seek on it without loading to RAM.
您应该在支持 64 位操作系统、64 位 Apache 版本和 PHP 相同的硬件上拥有 64 位操作系统。但这并不能保证与 PDF 一起使用的函数可以使用如此大的内存。您最好不要将整个文件加载到内存中,将其拆分为块或使用文件函数对其进行查找而不加载到 RAM。
回答by Wiggler Jtag
For others who are experiencing with the same problem, here is the description of the bug in php + patch https://bugs.php.net/bug.php?id=44522
对于遇到同样问题的其他人,这里是 php + 补丁中的错误描述 https://bugs.php.net/bug.php?id=44522
回答by Florent
Input the following to your Apache configuration:
在 Apache 配置中输入以下内容:
php_value memory_limit 2048M
回答by kishan Radadiya
You can also try this:
你也可以试试这个:
ini_set("max_execution_time", "-1");
ini_set("memory_limit", "-1");
ignore_user_abort(true);
set_time_limit(0);
回答by Radon8472
I had the same problem with commandline php even when ini_set("memory_limit", "-1");was set, so the limit is in php not from apache.
即使ini_set("memory_limit", "-1");设置了命令行 php,我也遇到了同样的问题,所以限制是在 php 中,而不是来自 apache。
You should check if you are using the 64bit version of php.
您应该检查您是否使用 64 位版本的 php。
Look at this question about Checking if code is running on 64-bit PHPto find out what php you are using.
查看有关检查代码是否在 64 位 PHP 上运行以找出您正在使用的 php 的问题。
I think your php is compiled in 32 bit.
我认为你的 php 是 32 位编译的。

