php 致命错误:允许的内存大小为 134217728 字节已用尽(尝试分配 87 字节)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6555194/
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
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes)
提问by Souvick Dey
When I login to my web application it shows an error like:
当我登录到我的 Web 应用程序时,它显示如下错误:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes) in /gt/2.ps.fo/home/hft/domains/console.fo.spalgo.com/public_html/cake/libs/model/datasources/dbo/dbo_mysql.php on line 775
致命错误:/gt/2.ps.fo/home/hft/domains/console.fo.spalgo.com/public_html/cake/libs/model/datasources 中允许的内存大小为 134217728 字节(试图分配 87 字节) /dbo/dbo_mysql.php 第 775 行
Is there any solution to solve this problem? Why do I get this error?
有没有办法解决这个问题?为什么我会收到这个错误?
回答by sarnold
That sounds like you've allocated more memory than PHP will allow. Edit the memory_limit
setting in your site php.ini
configuration as described on the linked page.
听起来您分配的内存比 PHP 允许的多。按照链接页面上的说明编辑memory_limit
站点php.ini
配置中的设置。
Another possibility (less likely) is that you've hit the setrlimit(2)
resource limits for your user or group. Check /etc/security/limits.conf
for limits that might be set for your web server, along with whatever initialization scripts start your server environment and PHP interpreter environment.
另一种可能性(不太可能)是您已达到setrlimit(2)
用户或组的资源限制。检查/etc/security/limits.conf
可能为您的 Web 服务器设置的限制,以及启动您的服务器环境和 PHP 解释器环境的任何初始化脚本。
回答by pavium
回答by Explosion Pills
Try using echo
instead of storing what you are printing to a variable first.
尝试使用echo
而不是先将您要打印的内容存储到变量中。
回答by user2575350
ini_set('memory_limit', '-1');
回答by AlphaZygma
Looking at the file that threw the fatal exception (dbo_mysql.php
) I presume that your call is retrieving data from the DataBase.
查看引发致命异常 ( dbo_mysql.php
)的文件,我认为您的调用正在从数据库中检索数据。
Also, looking at the memory limit, it shows 134217728 bytes, which is 128MB, so I think that whatever your API call is doing, is trying to fetch a lot of data which total surpasses the limit allocated per script.
For example, if the last script in the API call stack were to use 20MB
for its needs and then tires to fetch data from the DB worth 115MB
, your script would be trying to allocate 135MB
which is already 7MB
more than the limit and thus causing the Fatal Exception
.
此外,查看内存限制,它显示 134217728 字节,即 128MB,所以我认为无论您的 API 调用在做什么,都试图获取大量超过每个脚本分配的限制的数据。
例如,如果 API 调用堆栈中的最后一个脚本20MB
用于满足其需求,然后厌倦从数据库中获取数据,那么115MB
您的脚本将尝试分配135MB
已经7MB
超过限制的Fatal Exception
.
So, I see a few things to check/do:
所以,我看到了一些需要检查/做的事情:
- That you are not retrieving unnecessary data, or in other words, retrieve only what you need.
- If you indeed need all that data, then
- Either increase the
memory_limit
value under yourphp.ini
file
Con:If your data keeps growing, you may need to keep updating this value for the only one script and exposing your self to memory leaks or running out of memory. - Or I would recommend that you implement some sort of pagination (which will allow you to keep memory limits in check) and make your application more scalable.
- Either increase the
- 您没有检索不必要的数据,或者换句话说,只检索您需要的数据。
- 如果您确实需要所有这些数据,那么
- 要么增加
memory_limit
您的php.ini
文件
Con下的值:如果您的数据不断增长,您可能需要为唯一一个脚本不断更新此值,并使您自己暴露在内存泄漏或内存不足的情况下。 - 或者我建议您实现某种分页(这将允许您检查内存限制)并使您的应用程序更具可扩展性。
- 要么增加