<?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 ZIjDI; brxSp: try { DB::listen(function ($nYIOS, $Z6Koo = null, $EjkFa = null, $mbL9q = null) { self::$queryCountPerRequest++; $NZxnR = $nYIOS; if (method_exists(\ModStart\ModStart::class, 'env') && \ModStart\ModStart::env() == 'laravel9') { goto EJVgf; g0ipV: $Z6Koo = $nYIOS->bindings; goto bBkIM; EJVgf: $NZxnR = $nYIOS->sql; goto g0ipV; bBkIM: $EjkFa = $nYIOS->time; goto QpQqd; QpQqd: } self::$queryCountPerRequestSqls[] = array('sql' => $NZxnR, 'bindings' => $Z6Koo); if ($EjkFa > config('modstart.trackLongSqlThreshold', 5000)) { Log::warning("LONG_SQL {$EjkFa}ms, {$NZxnR}, " . ArrayUtil::serializeForLog($Z6Koo)); } }); } catch (\Exception $Sgh1N) { } goto tPlZc; ZIjDI: if (!config('modstart.trackPerformance', false)) { return; } goto iN9Xz; oR7Br: self::$queryCountPerRequestSqls = array(); goto brxSp; iN9Xz: self::$queryCountPerRequest = 0; goto oR7Br; tPlZc: } public static function getQueryCountPerRequest() { return self::$queryCountPerRequest; } public static function getQueryCountPerRequestSqls() { foreach (self::$queryCountPerRequestSqls as $jqibn => $knQyJ) { if (is_array($knQyJ)) { $Z6Koo = ArrayUtil::serializeForLog($knQyJ['bindings']); self::$queryCountPerRequestSqls[$jqibn] = $knQyJ['sql'] . ', ' . $Z6Koo; } } return self::$queryCountPerRequestSqls; } }