PHP/Apache 的内存上限
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4399138/
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
Upper memory limit for PHP/Apache
提问by spiderplant0
I'm getting the error when I run my PHP script....
运行 PHP 脚本时出现错误....
Fatal error: Out of memory (allocated 1827405824) (tried to allocate 88800 bytes)
I've added this line to my PHP script..
我已将此行添加到我的 PHP 脚本中..
ini_set("memory_limit","3000M");
This statement does seem to correctly control the memory usage, but I dont seem to be able to get it above about 1.8GB. Its as if the upper memory limit is being restricted somewhere else. I've also added to the php.ini...
此语句似乎确实正确控制了内存使用,但我似乎无法将其提高到大约 1.8GB 以上。就好像内存上限在其他地方受到限制。我还添加到 php.ini ...
memory_limit = 3000M
Does anyone know if the memory is restricted elsewhere?
有谁知道内存是否在其他地方受到限制?
I'm running a local server with Xampp. I have Windows 7, 64-bit with 4GB RAM. My script uses PHP's GD image library and I get the error when trying to allocate an image reference with ImageCreateTrueColor().
我正在使用 Xampp 运行本地服务器。我有带有 4GB RAM 的 64 位 Windows 7。我的脚本使用 PHP 的 GD 图像库,并且在尝试使用 ImageCreateTrueColor() 分配图像引用时出现错误。
(I know this is a huge amount of memory - but this is just a one-of script, and its just a lot easier to do it this way.)
(我知道这是一个巨大的内存量 - 但这只是一个脚本之一,而且这样做更容易。)
Thanks.
谢谢。
Update....
更新....
@elusive @Orbling I expect everybody's bored whith this question, but here is the simplified code which illustrates the problem.
@elusive @Orbling 我希望每个人都对这个问题感到厌烦,但这里是说明问题的简化代码。
<?php
ini_set("memory_limit","4000000000");
echo "ini_get = " . ini_get('memory_limit') . "<br>\n";
echo "memory_get_usage = " . memory_get_usage(true) . "<br>\n";
$bigImageHandle = imagecreatetruecolor(22200, 24800); //this is line 5
?>
Browser output...
浏览器输出...
ini_get = 4000000000
memory_get_usage = 524288
Fatal error: Out of memory (allocated 1843396608) (tried to allocate 88800 bytes) in
E:\User\My_Webs\experiments\houseshunting\temp\osMaps\t1.php on line 5
I tested this out with a smaller set of tiles and the memory used by imagecreatetruecolor() and I estimate I need 2.7GB
我用一组较小的图块和 imagecreatetruecolor() 使用的内存对此进行了测试,我估计我需要 2.7GB
回答by Reece45
You're running on a 64-bit operating system, but Apache and PHP are likely still 32-bit. If you're using mod_php, apache would be the limiting factor here.
您在 64 位操作系统上运行,但 Apache 和 PHP 可能仍然是 32 位。如果您使用的是 mod_php,那么 apache 将是这里的限制因素。
32-bit processes are limited about 2GiB of RAM unless you used the /3GB switch and the software is aware of 3GB support.
除非您使用 /3GB 开关并且软件知道 3GB 支持,否则 32 位进程的 RAM 限制约为 2GiB。
That still leaves up about 200 MiB that seems unused, but its small enough that it can be used by various libraries that all have to be loaded in memory
这仍然留下了大约 200 MiB 似乎未使用,但它足够小,可以被各种必须加载到内存中的库使用
As far as I know, the library usage won't show up in the committed memory, but still counts towards the 2GiB limit (much like device memory counts towards the 4GiB limit on 32-bit windows. Where installing 2 GiB graphics card brings you down to under 2GiB of usable RAM).
据我所知,库使用情况不会出现在提交的内存中,但仍计入 2GiB 限制(很像设备内存计入 32 位 Windows 上的 4GiB 限制。安装 2 GiB 显卡会给你带来什么)低至低于 2GiB 的可用 RAM)。
Most likely solution? Install a 64-bit PHP, and then dispatch it to that (using a system() call, perhaps)
最有可能的解决方案?安装 64 位 PHP,然后将其分发给它(可能使用 system() 调用)
回答by thenrion
Using Acquia Dev Desktop, I had many memory limit crashes.
使用 Acquia Dev Desktop,我有很多内存限制崩溃。
After having increased the memory limit into PHP.ini.
在将内存限制增加到 PHP.ini 之后。
php_value memory_limit 1024M
php_value max_execution_time 3000
This issue was less frequent but still occuring ( Especially with Feature Recreate )
此问题不那么频繁,但仍在发生(尤其是使用 Feature Recreate )
Into my httpd.conf I increased the StackThread to 16M
在我的 httpd.conf 中,我将 StackThread 增加到 16M
ThreadStackSize 16*1024*1024
And it solved the memory crash issue. Hope it can help
它解决了内存崩溃问题。希望它可以帮助
回答by Glitch Desire
The issue is likely to be caused by running 32-bit apache and php. Try upgrading these to 64-bit binaries and see if that fixes the issue.
该问题很可能是由运行 32 位 apache 和 php 引起的。尝试将这些升级到 64 位二进制文件,看看是否能解决问题。
回答by Orbling
Which PHP version are you using?
您使用的是哪个 PHP 版本?
The memory_limit variable is, or was, contained in a 32-bit integer, so can not go above 2GB.
memory_limit 变量现在或曾经包含在一个 32 位整数中,因此不能超过 2GB。
See: http://bugs.php.net/bug.php?id=39132&edit=1
见:http: //bugs.php.net/bug.php?id=39132&edit=1
From the bottom comment on that bug report, it might be the routine that translates the human readable form to a number, try putting it in digits.
从该错误报告的底部评论来看,它可能是将人类可读形式转换为数字的例程,请尝试将其放入数字中。
回答by JTigger
Check your Apache config (e.g., httpd.conf). There's likely an RLimitMEMdirective limiting the memory allow for children processes handling requests.
检查您的 Apache 配置(例如,httpd.conf)。可能有一个RLimitMEM指令限制了子进程处理请求的内存允许。
So, you can set your PHP limit all you want, if Apache spawns the process with a memory limit, you can't exceed that.
因此,您可以随心所欲地设置 PHP 限制,如果 Apache 生成具有内存限制的进程,则不能超过该限制。
If you're on a hosted service and have a shared server, likely you don't have access to this config and need to work with your provider. As you can see, it's configuration that applies server-wide... you're not likely going to get them to change this. Then again, if you're looking to spawn bigger than 1.5Gig processes, you prolly should be either solving the problem a different way (others have suggested this) or getting a dedicated server of some kind (e.g. EC2).
如果您使用托管服务并拥有共享服务器,则您可能无权访问此配置并需要与您的提供商合作。如您所见,它的配置适用于服务器范围……您不太可能让他们改变这一点。再说一次,如果您希望产生大于 1.5Gig 的进程,那么您应该要么以不同的方式解决问题(其他人已建议这样做),要么获得某种专用服务器(例如 EC2)。
For example:
例如:
/usr/local/apache/conf
#RLimitMEM 85643200 104857600 # Limit to: 80Mb / process, 100Mb total
RLimitMEM 134217728 537395200 # Limit to: 128Mb / Process, 512Mb total
回答by Vahan Margaryan
Try this
尝试这个
set_time_limit(300);
ini_set('memory_limit', '20000M');
回答by Pradeep Singh
Try this:
尝试这个:
#php_value memory_limit 300M
#php_value upload_max_filesize 200M
#php_value post_max_size 200M
#php_value max_execution_time 80000
#php_value max_input_time 80000
回答by Ivan Smorodin
try ini_set('memory_limit', '-1');
尝试 ini_set('memory_limit', '-1');