vendor\laravel\framework\src\Illuminate\Database\Connection.php
中的 696 行是导致问题的根源。
public function logQuery($query, $bindings, $time = null) { $this->event(new QueryExecuted($query, $bindings, $time, $this)); //内存泄露是这行代码导致的 if ($this->loggingQueries) { $this->queryLog[] = compact('query', 'bindings', 'time'); } }
查找了文档发现没有可以关闭该方法的配置。然后有去了github 查找是否有解决办法。 因为知道问题出现点。我搜索 logQuery 找到 https://github.com/laravel/framework/issues/30012
,里面提到解决方法。在需要的地方添加 DB::getConnection()->unsetEventDispatcher();
代码。结果添加发现报错,没有该方法。在源代码中搜索 unsetEventDispatcher
发现存在该方法。然后查询类的关系。 修改后可以使用,在需要的地方添加
$query = DB::table('test'); $query->getConnection()->unsetEventDispatcher();
这样就可以解决该问题。
参考:
https://learnku.com/laravel/t/52660
最新评论: