Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用雄辩的查询将耗尽允许的内存限制_Php_Mysql_Laravel_Eloquent - Fatal编程技术网

Php 使用雄辩的查询将耗尽允许的内存限制

Php 使用雄辩的查询将耗尽允许的内存限制,php,mysql,laravel,eloquent,Php,Mysql,Laravel,Eloquent,我有一个非常非常简单的问题 select * from `users` where (`active` = 1 and `newsletter` = 1) and (`terminated` = 0 or (`terminated` = 1 and `newsletter_terminated` = 1)); 我用这样的雄辩语言构建它(当我使用toSql() 但是当我执行这个脚本时,我得到了一个错误 Fatal error: Allowed memory size of 134217728

我有一个非常非常简单的问题

select * 
from `users` 
where (`active` = 1 and `newsletter` = 1) and (`terminated` = 0 or (`terminated` = 1 and `newsletter_terminated` = 1));
我用这样的雄辩语言构建它(当我使用
toSql()

但是当我执行这个脚本时,我得到了一个错误

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) in /xxx/eloquent/vendor/illuminate/database/Illuminate/Database/Connection.php on line 303
当我在
get
方法中编写特定的列时,比如
get(['id']);
它可以正常工作。但是我仍然不明白为什么它不能正常工作。似乎内存泄漏,但是在哪里


当我在SQL客户机中执行查询时,查询在3毫秒内完成,因此看起来没有太多数据。不幸的是,我没有在vagrant box上安装xdebug,因此我当前无法获取stacktrace。

我也遇到过类似的问题,我认为这不是特定于Laravel的——这与嵌入式闭包。基本上,对于解释这些闭包的进程,您的内存溢出了128MB,而这对于嵌入式闭包来说可能还不够


或者尝试增加php.ini中的内存限制(512MB就可以了),展开闭包,或仅使用原始SQL语句进行查询。

我也遇到类似情况。请检查模型中的$with属性。可能自动加载的关系太多。请尝试不要这样做。每个对象都分配内存。如果有15000行具有多个关系,并且渴望加载每个行,则内存blows-away。我已结束编写原始mysql查询,问题已得到解决。

当您对表中的所有列使用get(['field1','field2',…])时会发生什么?遗憾的是,这会返回相同的错误查询返回多少条记录?您可以使用
chunk()
method。请参阅文档部分分块结果。问题是,我正在尝试进行CSV导出,因此我需要一次所有这些结果。我使用的是eloquent,而不是laravel(为更多视图添加了标记),但我无法使用它对eloquent进行原始查询,对吗?
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) in /xxx/eloquent/vendor/illuminate/database/Illuminate/Database/Connection.php on line 303