php 致命错误:允许的 67108864 字节内存大小已用完(尝试分配 122880 字节)

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

Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 122880 bytes)

phpwordpressmemory-limit

提问by tudorvisanmiu

I have two domains, webhosted on 000webhost. I installed wordpress on them and for some days it functioned well, but now it shows me the following error on both of them:

我有两个域,在 000webhost 上托管。我在它们上安装了 wordpress 并且有几天它运行良好,但现在它向我显示了它们两个的以下错误:

Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 122880 bytes)

致命错误:允许的 67108864 字节内存大小已用完(尝试分配 122880 字节)

The source of the error ("in...") is never the same (it always changes).

错误的来源(“in...”)永远不会相同(它总是在变化)。

I found that this error is common, but here I don't have a php.ini file. I understood that I should change the wp-config file. Well, here's the catch: how should I do this? I understood that I should add

我发现这个错误很常见,但是这里我没有 php.ini 文件。我知道我应该更改 wp-config 文件。嗯,这里有一个问题:我应该怎么做?我明白我应该添加

define (‘WP_MEMORY_LIMIT', ‘...M'); // increase limit to ..M" (adding 64, 96 or 128) 

[thanks to http://www.dummies.com/how-to/content/optimizing-the-wordpress-configuration-file.html]

[感谢http://www.dummies.com/how-to/content/optimizing-the-wordpress-configuration-file.html]

I'm not good at programming (just a newbie who wants his own domain), can you help me? Please there me EXACTLY where to put the function. If this is not how to solve the problem, please offer me another solution. I am quite in a great need of help :)

我不擅长编程(只是一个想要自己域的新手),你能帮我吗?请在那里我确切地放置该功能。如果这不是解决问题的方法,请提供另一种解决方案。我非常需要帮助:)

I can't post the file here (it seems I don't format it well), but I can explain the structure:

我不能在这里发布文件(似乎我的格式不太好),但我可以解释一下结构:

  1. introduction: "* The base configurations of the WordPress. [...]
  2. After that, MySQL data.
  3. Then, "Authentication Unique Keys and Salts."
  4. "WordPress Database Table prefix"
  5. "WordPress Localized Language, defaults to English"
  6. "For developers: WordPress debugging mode"
  7. " That's all, stop editing! Happy blogging."
  1. 介绍:“* WordPress 的基本配置。[...]
  2. 之后,MySQL 数据。
  3. 然后是“身份验证唯一密钥和盐”。
  4. “WordPress 数据库表前缀”
  5. “WordPress 本地化语言,默认为英语”
  6. “对于开发者:WordPress 调试模式”
  7. “就是这样,停止编辑!祝博客愉快。”

So, where should I introduce the definefunction (if in this file, where?), if in another, which and where?

那么,我应该在哪里引入define函数(如果在这个文件中,在哪里?),如果在另一个文件中,在哪里?

回答by Joachim Isaksson

For 000webhost, you should be able to override php.ini values using a .htaccessfile stored in your public_html.

对于 000webhost,您应该能够使用.htaccess存储在 public_html 中的文件覆盖 php.ini 值。

I'm not sure what values they allow you to override, but to raise the memory limit to 128M (the standard, I presume it was lowered to 64M), try putting this in .htaccess;

我不确定它们允许您覆盖哪些值,但要将内存限制提高到 128M(标准,我认为它已降低到 64M),请尝试将其放入.htaccess;

php_value memory_limit 128M

回答by Vimalnath

If you don't have access to php.ini and updating .htacess file gives you Internal Server Erroryou could try to add this line in wp-settings.php

如果您无权访问 php.ini 并且更新 .htacess 文件让Internal Server Error您可以尝试在wp-settings.php

ini_set('memory_limit', '128M');

回答by Niet the Dark Absol

Changing the memory limit only hides the problem, it doesn't solve it.

更改内存限制只会隐藏问题,并不能解决问题。

You currently have 64MB of memory, which should be more than enough for your needs. If it's not, then there's almost certainly a leak in your code, or possibly an infinite loop.

您目前拥有 64MB 的内存,这应该足以满足您的需求。如果不是,那么几乎可以肯定您的代码存在泄漏,或者可能是无限循环。

Instead of trying to hide the error in a corner, try fixing it. Look at where the error happens, see if you can find what the "last straw" is that makes it exceed the memory limit.

不要试图将错误隐藏在角落里,而是尝试修复它。查看错误发生的位置,看看您是否可以找到使其超出内存限制的“最后一根稻草”。

回答by Rony Samuel

GoDaddy seems to reduce the memory_limit value to 64M by default.

GoDaddy 似乎默认将 memory_limit 值减少到 64M。

I had spend a day or two trying to increase the size, by changing the .htaccess file and php.ini file in the /public_html folder. But atlast I got the issue resolved as follows:

我花了一两天时间试图通过更改 /public_html 文件夹中的 .htaccess 文件和 php.ini 文件来增加大小。但最终我得到了如下解决的问题:

  • Logged into Control Centre
  • Opened CGI Admin > PHP
  • Opened the phpmyinfo of my PHP version in the page (4 & 5 were shown, and mine was PHP5)
  • On the first line, there is a note specifying that "the configuration shown is not from the user's php5.inifile". Guessed the ini file to be php5.iniand not php.ini
  • Created a new file with all the configurations copied from the php.ini file in the root folder, and named it php5.ini
  • Added a new line memory_limit = 128M
  • Uploaded it to the root folder (/public_html) and it worked.
  • 登录控制中心
  • 打开 CGI 管理 > PHP
  • 在页面中打开我的PHP版本的phpmyinfo(显示的是4&5,我的是PHP5)
  • 在第一行,有一个注释指定“显示的配置不是来自用户的php5.ini文件”。猜测ini文件是php5.ini而不是php.ini
  • 创建一个新文件,其中包含从根文件夹中的 php.ini 文件复制的所有配置,并将其命名为 php5.ini
  • 新增一行 memory_limit = 128M
  • 将它上传到根文件夹(/public_html)并且它起作用了。

回答by Sanchitos

If you are using GoDaddy you should check which php version is your hosting running.

如果您使用的是 GoDaddy,您应该检查您的主机运行的是哪个 php 版本。

Happened to me that I was running 5.2 when the latest available was 5.4.

发生在我身上,当最新可用的是 5.4 时,我正在运行 5.2。

You just have to log in to the hosting manager and check the version in Programming Languages.

您只需要登录托管管理器并在编程语言中检查版本。

enter image description here

在此处输入图片说明

回答by Akshay

its well-known error easy to solve just do simple editing wp-config.phpfile First, open your wp-config.php which is located in the root WordPress directory. Then add the following line inside the main php tag: define('WP_MEMORY_LIMIT', '64M');or change 64M to your need.

其众所周知的错误很容易解决,只需简单编辑wp-config.php文件首先,打开位于 WordPress 根目录中的 wp-config.php。然后在主 php 标签中添加以下行: define('WP_MEMORY_LIMIT', '64M');或根据需要更改 64M。

回答by Mohammad Tajul Islam

Go to wp-config.php file and put this code right under the very 1st php line (so this code will go on line 2 and 3)

转到 wp-config.php 文件并将此代码放在第一个 php 行下方(因此此代码将在第 2 行和第 3 行)

//increase WP Memory Limit    
define('WP_MEMORY_LIMIT', '256M');