增加 PHP 内存限制(Apache、Drupal6)

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

Increase PHP Memory limit (Apache, Drupal6)

phpapachedrupaldrupal-6memory-limit

提问by Nick Heiner

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.)

我正在尝试在共享托管服务器上运行 Drupal 安装。(我只是订阅了一个提供商——我不拥有这个盒子。)

I need to increase the PHP memory limit for my Apache server. I have tried

我需要增加我的 Apache 服务器的 PHP 内存限制。我试过了

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:

在 settings.php (包含在每个请求中的文件)中,但这会导致内部服务器错误 500。如果我将其取出,则会出现此错误:

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?

附带问题:19456 小于 33554432。为什么说允许的大小已用完?

I also tried putting this in on .htaccess:

我也试过把它放在 .htaccess 上:

 php_value memory_limit                 128M 

This had no effect.

这没有效果。

回答by Pascal MARTIN

The error message you are getting :

您收到的错误消息:

Allowed memory size of 33554432 bytes exhausted (tried to allocate 19456 bytes)

允许的内存大小为 33554432 字节耗尽(尝试分配 19456 字节)

Indicates that you are trying to allocate more than the 33554432 bytes you are allowed to use ; ie 32 MB :

表示您正在尝试分配超过允许使用的 33554432 字节;即 32 MB:

; 33554432/1024/1024
        32

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.

它表明分配失败是在 PHP 尝试分配 19 KB 时;但是已经分配了将近 32MB——这些分配没有失败,因为它们的总数不到 32MB。

The "19456 bytes" part of the error message is not what is really relevant : what is relevant is that your memory_limitis set at 32 MB.

错误消息的“19456 字节”部分并不是真正相关的:相关的是您memory_limit设置为 32 MB。


Considering the memory_limitis some kind of security, it would be strange that your hosting provider allows you to change its value...


考虑到这memory_limit是某种安全性,您的托管服务提供商允许您更改其值会很奇怪......

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)

顺便说一句:32MB 实际上是一个相当合理的值——我从未见过配置为允许 Web 应用程序使用超过 32 MB 的服务器......并且根据手册,PHP 5.2 的默认值似乎是 16 MB 。
(我已经和 Drupal 一起工作了几个月)


About the error 500, I don't have a lot of ideas... One possibility might be that the safe_modeis activated, and that it doesn't allow setting the memory_limit at execution time.


关于错误500,我没有太多想法......一种可能safe_mode是激活了,并且它不允许在执行时设置memory_limit。

The manual doesn't see to say much about that, but there is a bit of information under the max_execution_timedirective :

该手册并没有看到太多关于这一点的内容,但是该max_execution_time指令下有一些信息:

You can not change this setting with ini_set()when running in safe mode. The only workaround is to turn off safe mode or by changing the time limit in the php.ini.

ini_set()在安全模式下运行时,您无法更改此设置 。唯一的解决方法是关闭安全模式或更改 php.ini 中的时间限制。

I suppose the same is true about memory_limit; it would seem logical, anyway.

我想同样适用于memory_limit; 无论如何,这似乎是合乎逻辑的。

回答by jergason

Put it in your php.ini file. Ask your host to restart Apache. Thisnode 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."

把它放在你的 php.ini 文件中。要求您的主机重新启动 Apache。drupal.org 上的这个节点将引导您完成如何操作。如果您有共享主机,则有关于如何为 drupal.org 上大多数更受欢迎的提供商更改 php.ini 的分步指南。只需搜索“PROVIDER_NAME 增加内存限制”。

回答by Beyerz

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

但是,当涉及到 drupal 时,添加是正确的

ini_set('memory_limit', 'xxxM');

to the settings.php file. (xxx = the required memory)

到 settings.php 文件。(xxx = 所需内存)

Drupal has a lot of fail safes, this is one of them and drupal stops you from exhausting your memory.

Drupal 有很多故障保险柜,这是其中之一,drupal 可以防止您耗尽内存。

So check with you hosting company, get it increased and set your memory_limit in the settings.php file.

因此,请与您的托管公司联系,增加它并在 settings.php 文件中设置您的 memory_limit。

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.

为其他遇到类似问题并在 drupal 中使用多种方法解决此问题的人阅读本文。

http://drupal.org/node/29268

http://drupal.org/node/29268

Good luck

祝你好运

回答by JTigger

If you're setting memory_limitand getting out of memory errors less than the maximum, one culprit lies with the upstream system spawning your process: Apache.

如果您设置memory_limit和获取的内存不足错误小于最大值,则罪魁祸首在于产生您的进程的上游系统: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.

在 Apache 配置 ( /usr/local/apache/conf/httpd.conf) 中,您将找到一个指令,该指令为处理请求的所有子进程设置上限(并且 Drupal 正在此类进程中运行)。一个给定的 Apache 服务器可能会处理多个客户(您和其他一些人)。如果他们允许一个客户占用所有内存,那么其他所有人都会有一个 BadTime(tm)。为了避免这种情况,他们将限制每个此类进程可以拥有的内存量。

For example:

例如:

# rlimits, do not modify
#  Setting single-process size 
#RLimitMEM 85643200 104857600
RLimitMEM 134217728 537395200

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.

FWIW,Host Gator 似乎每个进程给你大约 80Mb。PHP 运行时似乎需要大约 16Mb。

回答by Simon Groenewolt

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).

询问您的提供商为什么它不起作用。我猜他们限制了您可以使用的内存量,并且不允许将其设置得更高,或者您在虚拟主机中运行,而该主机根本没有您请求的内存量(这可能是导致错误 500)。

回答by Amber

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.

许多共享主机提供商不允许您提高 PHP 的内存限制,因为他们不希望共享机器上的一个站点占用同一台机器上其他站点的内存。我建议阅读您的托管服务提供商的常见问题解答以及有关 PHP 的内容,它可能会在那里列出任何此类限制。

Side question: 19456 is less than 33554432. Why is it saying that allowed size is exhausted?

附带问题:19456 小于 33554432。为什么说允许的大小已用完?

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.

较小的数字只是导致总分配量超过限制的请求大小 - 而不是所有分配请求的实际总数。因此,如果已经分配了 33540000 个字节,并且请求了另一个大小为 19456 的对象,那么您将收到该消息。