webman中间件监听sql;回调打印sql语句时自增

sunsgne

public function process(Request $request, callable $next) : Response
{
Db::connection()->listen(function (QueryExecuted $queryExecuted){
dump("[{$queryExecuted->time} ms] {$queryExecuted->sql}");
});
return $next($request);
}
截图

 每次请求都会多加一条sql
1870 1 1
1个回答

walkor

你这样放到中间件里,每次请求都会重复调用Db::connection()->listen,所以sql打印会重复。

参考手册加一个bootstrap,bootstrap只会在启动时只会执行一次,把Db::connection()->listen放在bootstrap里就好了

https://www.workerman.net/doc/webman/others/bootstrap.html

年代过于久远,无法发表回答
🔝