php 已用完允许的 262144 字节内存大小(尝试分配 24576 字节)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16175153/
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
Allowed memory size of 262144 bytes exhausted (tried to allocate 24576 bytes)
提问by monxas
I was going crazy with this.
我快要疯了。
I got the next message:
我收到下一条消息:
Allowed memory size of 262144 bytes exhausted (tried to allocate 24576 bytes)
TODO LIST
待办事项清单
Check phpinfo(), got the right php.ini route and edit it. Change memory_limit to
检查 phpinfo(),找到正确的 php.ini 路由并编辑它。将 memory_limit 更改为
memory_limit = 128M
Make sure the value memory_limit changes con phpinfo() with the result:
确保值 memory_limit 更改 con phpinfo() 的结果:
memory_limit 128MB 128MB
Check .htaccess and added (not needed)
检查 .htaccess 并添加(不需要)
php_value memory_limit 128M
And also to change it via php like so (before error line):
并且还可以像这样通过 php 更改它(在错误行之前):
ini_set('memory_limit','128M');
It says everywhere that memory is set to 128M, but still get that error?
到处都说内存设置为128M,但仍然出现错误?
The error is in Swift library (library for sending emails), in abstractSmtpTransport.php, so it's not my code int's suposed to work.
错误在 Swift 库(用于发送电子邮件的库)中,在 abstractSmtpTransport.php 中,所以我的代码 int 不应该工作。
Any ideas???
有任何想法吗???
Edit: Yes, the previous was done restarting apache.
编辑:是的,之前完成了重新启动 apache。
EDIT 2: @patrick, added that but nothing was echoed
编辑 2:@patrick,补充说,但没有回应
Tryed with lower value, 28M int every file, restarted apache, same error (phpinfo showed new value)
尝试使用较低的值,每个文件 28M int,重新启动 apache,同样的错误(phpinfo 显示新值)
tried with -1, restarting, and same error.
尝试使用 -1,重新启动和相同的错误。
EDIT 3: isn't it weird that allowed memory is bigger than allocated memory? (despite the fact that allowed memory size is way below real allowed memory asigned)
编辑 3:允许的内存大于分配的内存是不是很奇怪?(尽管允许的内存大小远低于分配的实际允许内存)
回答by kael
I see my problem is a little bit different from yours, but I'll post this answer in case it helps someone else. I was using MB
as shorthand instead of M
when defining my memory_limit, and php was silently ignoring it. I changed it to an integer (in bytes) and the problem was solved.
我发现我的问题与你的有点不同,但我会发布这个答案,以防它对其他人有帮助。我在定义 memory_limit 时使用的MB
是速记M
,而 php 默默地忽略了它。我把它改成一个整数(以字节为单位),问题就解决了。
My php.ini changed as follows: memory_limit = 512MB
to memory_limit = 536870912
. This fixed my problem. Hope it helps with someone else's! You can read up on php's shorthand here.
我的 php.ini 更改如下:memory_limit = 512MB
到memory_limit = 536870912
. 这解决了我的问题。希望对别人有帮助!你可以在这里阅读 php 的速记。
Good luck!
祝你好运!
Edit
编辑
As Yaodong points out, you can just as easily use the correct shorthand, "M", instead of using byte values. I changed mine to byte values for debugging purposes and then didn't bother to change it back.
正如姚东指出的那样,您可以轻松地使用正确的简写“M”,而不是使用字节值。出于调试目的,我将我的值更改为字节值,然后就懒得改回去了。
回答by Ethan
The value of 262,144 bytes is the key to the diagnosis. You'll see this magic number pop up in PHP questions all over the place. Why? Because that is the value PHP will end up with as its memory limit if you attempt to update the limit with a value it can't use. An empty string will produce this memory limit, as will an incorrect unit notation like '128MB' instead of the correct '128M'.
262,144 字节的值是诊断的关键。你会看到这个神奇的数字出现在到处都是 PHP 问题中。为什么?因为如果您尝试使用它无法使用的值更新限制,那么这就是 PHP 最终将作为其内存限制的值。空字符串将产生此内存限制,错误的单位符号(如“128MB”而不是正确的“128M”)也会产生此限制。
262,144 bytes is exactly 256 Kibibytes. Why PHP runs home to that value when it gets confused is beyond me.
262,144 字节正好是 256 Kibibytes。为什么 PHP 在感到困惑时会回到那个值,这超出了我的理解。
isn't it weird that allowed memory is bigger than allocated memory?
允许的内存大于分配的内存是不是很奇怪?
The allocated amount shown is just the most recent allocation attempt, the one that ran afoul of the memory limit. See Allowed memory size in PHP when allocating less.
显示的分配数量只是最近的分配尝试,与内存限制冲突的尝试。请参阅在分配较少时 PHP 中允许的内存大小。
回答by Tuan
See if this answer can help you. Particularly the fact that CLI ini could be different than when the script is running through a browser.
看看这个答案能不能帮到你。特别是 CLI ini 可能与脚本通过浏览器运行时不同。
回答by Pratik Patel
In my case neither M
or G
helped, so I have converted allocated memory to bytes using: https://www.gbmb.org/mb-to-bytes
在我的情况没有M
或G
帮助,所以我已经转换分配的内存使用字节:https://www.gbmb.org/mb-to-bytes
4096M = 4294967296
4096M = 4294967296
php.ini:
php.ini:
memory_limit = 4294967296
memory_limit = 4294967296
回答by Wes Candela
I was trying to up the limit Wordpress sets on media uploads. I followed advice from some blog I'm not going to mention to raise the limit from 64MB to 2GB.
我试图提高 Wordpress 对媒体上传设置的限制。我遵循了一些博客的建议,我不会提到将限制从 64MB 提高到 2GB。
I did the following:
我做了以下事情:
Created a (php.ini) file in WP ADMIN with the following integers:
使用以下整数在 WP ADMIN 中创建了一个 (php.ini) 文件:
upload_max_filesize = 2000MB
post_max_size = 2100MV
memory_limit = 2300MB
I immediately received this error when trying to log into my Wordpress dashboard to check if it worked:
我在尝试登录我的 Wordpress 仪表板以检查它是否有效时立即收到此错误:
“Allowed memory size of 262144 bytes exhausted (tried to allocate 24576 bytes)"
“允许的内存大小为 262144 字节耗尽(尝试分配 24576 字节)”
The above information in this chain helped me tremendously. (Stack usually does BTW)
这个链中的上述信息对我帮助很大。(堆栈通常是 BTW)
I modified the PHP.ini file to the following:
我将 PHP.ini 文件修改为以下内容:
upload_max_filesize = 2000M
post_max_size = 2100M
memory_limit = 536870912M
The major difference was only use M, not MB, and set that memory limit high.
主要区别是只使用 M,而不是 MB,并将内存限制设置得很高。
As soon as I saved the changed the PHP.ini file, I saved it, went to login again and the login screen reappeared.
一旦我保存了更改后的 PHP.ini 文件,我就保存了它,再次登录并重新出现登录屏幕。
I went in and checked media uploads, ands bang:
我进去检查了媒体上传,然后砰的一声:
图像显示了 twordpress 媒体文件夹“添加新”框,限制为“最大上传文件大小:2 GB”
I haven't restarted Apache yet… but all looks good.
我还没有重新启动 Apache……但一切看起来都不错。
Thanks everyone.
谢谢大家。
回答by daniel
In my case it was because I had another folder that contained xampp and all it's files (htdocs, php e.t.c). Like I installed Xampp twice in different directories and for some reason the configurations of the other one was affecting my current xampp directory and so I had to change the memory size in the php.ini file of the other directory too.
就我而言,这是因为我有另一个文件夹,其中包含 xampp 及其所有文件(htdocs、php 等)。就像我在不同的目录中安装了两次 Xampp 一样,由于某种原因,另一个的配置影响了我当前的 xampp 目录,因此我也不得不更改另一个目录的 php.ini 文件中的内存大小。