<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Core\Monitor; use Illuminate\Database\Events\QueryExecuted; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use ModStart\Core\Util\ArrayUtil; class DatabaseMonitor { private static $queryCountPerRequest = 0; private static $queryCountPerRequestSqls = array(); public static function init() { goto xFg6x; cMqQj: self::$queryCountPerRequest = 0; goto rRvjY; x_DuW: try { DB::listen(function ($qeoqS, $QG5bU = null, $oWzL0 = null, $y8wFV = null) { self::$queryCountPerRequest++; $mYKgC = $qeoqS; if (method_exists(\ModStart\ModStart::class, 'env') && \ModStart\ModStart::env() == 'laravel9') { goto WOvxr; WOvxr: $mYKgC = $qeoqS->sql; goto Kkt27; Bob3u: $oWzL0 = $qeoqS->time; goto n0ggg; Kkt27: $QG5bU = $qeoqS->bindings; goto Bob3u; n0ggg: } self::$queryCountPerRequestSqls[] = array('sql' => $mYKgC, 'bindings' => $QG5bU); if ($oWzL0 > config('modstart.trackLongSqlThreshold', 5000)) { Log::warning("LONG_SQL {$oWzL0}ms, {$mYKgC}, " . ArrayUtil::serializeForLog($QG5bU)); } }); } catch (\Exception $tZVhb) { } goto b02Vg; xFg6x: if (!config('modstart.trackPerformance', false)) { return; } goto cMqQj; rRvjY: self::$queryCountPerRequestSqls = array(); goto x_DuW; b02Vg: } public static function getQueryCountPerRequest() { return self::$queryCountPerRequest; } public static function getQueryCountPerRequestSqls() { foreach (self::$queryCountPerRequestSqls as $Xn_Rr => $pk5fc) { if (is_array($pk5fc)) { $QG5bU = ArrayUtil::serializeForLog($pk5fc['bindings']); self::$queryCountPerRequestSqls[$Xn_Rr] = $pk5fc['sql'] . ', ' . $QG5bU; } } return self::$queryCountPerRequestSqls; } }