增加 PHP 内存限制(Apache、Drupal6)
我正在尝试在共享托管服务器上运行 Drupal 安装。 (我只是订阅了一个提供商 - 我不拥有该盒子。)
我需要增加我的 Apache 服务器的 PHP 内存限制。我已经
ini_set('memory_limit', '64M');
在 settings.php (每个请求中包含的文件)中进行了尝试,但这会导致内部服务器错误 500。如果我将其取出,则会收到此错误:
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 19456 bytes)...
附带问题:19456 小于 33554432。为什么会这样说允许的大小已用尽?
我还尝试将其放在 .htaccess 上:
php_value memory_limit 128M
这没有效果。
I'm trying to run a Drupal installation on a shared hosting server. (I'm just subscribing to a provider - I don't own the box.)
I need to increase the PHP memory limit for my Apache server. I have tried
ini_set('memory_limit', '64M');
in settings.php (a file that is included in every request), but this causes Internal Server Error 500. If I take it out, I get this error:
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 19456 bytes)...
Side question: 19456 is less than 33554432. Why is it saying that allowed size is exhausted?
I also tried putting this in on .htaccess:
php_value memory_limit 128M
This had no effect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您收到的错误消息:
表示您正在尝试分配超过允许使用的 33554432 字节;即32 MB:
表示PHP尝试分配19 Kbytes时分配失败;但是已经分配了近 32MB - 这些分配并没有失败,因为它们的总量小于 32MB。
错误消息的“19456 字节”部分并不是真正相关的:相关的是您的
memory_limit
设置为 32 MB。考虑到内存限制是某种安全性,您的托管提供商允许您更改其值会很奇怪...
如果您使用共享托管,则意味着服务器上的任何人都可以获取他们想要任何数量的内存...这对于同一服务器上的其他用户来说不太好!
顺便说一句:32MB 实际上是一个相当合理的值——我从未见过服务器配置为允许 Web 应用程序使用超过 32 MB 的空间...根据 手册。
(我已经使用 Drupal 几个月了)
关于错误 500,我没有太多想法...一种可能是
safe_mode
已激活,并且不允许在执行时设置 memory_limit。该手册没有对此进行太多说明,但在
max_execution_time
指令:我想
memory_limit
也是如此;无论如何,这似乎是合乎逻辑的。The error message you are getting :
Indicates that you are trying to allocate more than the 33554432 bytes you are allowed to use ; ie 32 MB :
It indicates that the allocation that failed was when PHP tryied to allocate 19 Kbytes ; but there had already been almost 32MB allocated -- those allocations did not fail, as their total was less than 32 MB.
The "19456 bytes" part of the error message is not what is really relevant : what is relevant is that your
memory_limit
is set at 32 MB.Considering the
memory_limit
is some kind of security, it would be strange that your hosting provider allows you to change its value...If you are on shared hosting, it would mean that anyone on the server could get any amount of memory they want... Which would not be that nice for the other users on the same server !
BTW : 32MB is actually a quite reasonable value -- I've never seen a server configured to allow more than 32 MB for a web application... And the default value for PHP 5.2 seems to be 16 MB, according to the manual.
(And I've been working with Drupal for a couple of months)
About the error 500, I don't have a lot of ideas... One possibility might be that the
safe_mode
is activated, and that it doesn't allow setting the memory_limit at execution time.The manual doesn't see to say much about that, but there is a bit of information under the
max_execution_time
directive :I suppose the same is true about
memory_limit
; it would seem logical, anyway.将其放入 php.ini 文件中。要求您的主机重新启动 Apache。 drupal.org 上的此节点将引导您完成操作。如果您有共享主机,drupal.org 上有关于如何更改大多数较受欢迎的提供商的 php.ini 的分步指南。只需搜索“PROVIDER_NAME 增加内存限制”即可。
Put it in your php.ini file. Ask your host to restart Apache. This node on drupal.org walks you through how to do it. If you have shared hosting, there are step-by-step guides on how to change your php.ini for most of the more popular providers on drupal.org. Just search for "PROVIDER_NAME increase memory limit."
您需要向您的托管公司验证他们允许您使用多少内存,因为只有他们才能更改它,如果他们不增加内存,那么我建议寻找一家新的托管公司。
然而,当谈到 drupal 时,您添加
到 settings.php 文件是正确的。 (xxx = 所需的内存)
Drupal 有很多故障保险柜,这就是其中之一,drupal 可以防止您耗尽内存。
因此,请咨询您的托管公司,增加它并在 settings.php 文件中设置您的内存限制。
我通常只是将这一行添加到脚本的最底部,但您实际上可以将其添加到任何地方。
为其他有类似问题并且有多种方法在 drupal 中解决此问题的人阅读本文。
http://drupal.org/node/29268
祝你好运
You need to verify with your hosting company how much memory they have allowed you as only they will be able to change it, if they won't increase it, then I suggest looking for a new host company.
However when it comes to drupal, you were correct to add
to the settings.php file. (xxx = the required memory)
Drupal has a lot of fail safes, this is one of them and drupal stops you from exhausting your memory.
So check with you hosting company, get it increased and set your memory_limit in the settings.php file.
I usually just add this line at the very bottom of the script, but you can really add it anywhere.
Read this for other people that had a similar problem and had numerous methods to solve this in drupal.
http://drupal.org/node/29268
Good luck
如果您设置了内存限制并且内存不足错误小于最大值,那么罪魁祸首就是生成您的进程的上游系统:Apache。
在 Apache 配置 (
/usr/local/apache/conf/httpd.conf
) 中,您会发现一个指令,该指令为处理请求的所有子进程设置上限(Drupal 运行在这样的环境中)过程)。一个给定的 Apache 服务器可以处理多个客户(您和其他一些人)。如果他们允许一个客户霸占所有内存,那么其他人都会遇到麻烦。为了避免这种情况,他们将限制每个此类进程可以拥有的内存量。例如:
在这里,我注释掉了我的托管服务设置的原始值并增加了它们。
当然,如果您位于共享服务器上,那么您不太可能更改此配置。事实上,这可能是您的主机提供商会更改的配置。
FWIW,Host Gator 似乎为每个进程提供了约 80Mb。 PHP 运行时似乎需要约 16Mb。
If you're setting
memory_limit
and getting out of memory errors less than the maximum, one culprit lies with the upstream system spawning your process: Apache.In Apache configuration (
/usr/local/apache/conf/httpd.conf
), you'll find a directive that sets an upper limit for all child processes that handle requests (and Drupal is running in such processes). A given Apache server may handle multiple customers (you and some number of others). If they allowed one customer to hog all the memory, everyone else would be having a BadTime(tm). To avoid that situation, they'll cap how much memory each such process can have.For example:
Here, I've commented out the original values set by my hosting service and increased them.
Of course, if you are on a shared server, then it's highly unlikely you can change this configuration. In fact, this is likely the configuration your host provider would change.
FWIW, Host Gator seems to give you ~80Mb per process. The PHP runtime seems to take ~16Mb.
询问您的提供商为什么它不起作用。我猜他们限制了您可以使用的内存量,并且不允许将其设置得更高,或者您正在一个虚拟主机内运行,而该虚拟主机根本没有您请求的内存量(这可能是导致错误 500)。
Ask your provider why it does not work. I would guess they limited the amount of memory you can use and do not allow it to be set any higher, or you are running inside a virtual host that simply does not have the amount of memory you request (That could be the cause of the error 500).
许多共享主机提供商不允许您提高 PHP 的内存限制,因为他们不希望共享主机上的一个站点占用同一台计算机上其他站点的内存。我建议您阅读托管提供商的常见问题解答以及有关 PHP 的内容,其中可能列出了任何此类限制。
较小的数字只是导致分配总量超过限制的请求大小,而不是所有分配请求的实际总量。因此,如果已经分配了 33540000 字节,并且请求了另一个大小为 19456 的对象,那么您将收到该消息。
Many shared hosting providers will not allow you to raise PHP's memory limit, as they don't want one site on a shared box hogging memory from other sites on the same machine. I'd recommend reading your hosting provider's FAQs and whatnot regarding PHP, it may list any such limitation there.
The smaller number is just the size of the request which caused the total allocated amount to go over the limit - not the actual total across all allocation requests. So if 33540000 bytes were already allocated, and another object of size 19456 were requested, then you'd get that message.