<?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 ktr7x; ktr7x: if (!config('modstart.trackPerformance', false)) { return; } goto XKDJt; viAxY: self::$queryCountPerRequestSqls = array(); goto sBspJ; sBspJ: try { DB::listen(function ($lpymm, $CGIOU = null, $ANM3E = null, $RpS7B = null) { self::$queryCountPerRequest++; $fxyYQ = $lpymm; if (method_exists(\ModStart\ModStart::class, 'env') && \ModStart\ModStart::env() == 'laravel9') { goto GtZ1v; oSnfm: $ANM3E = $lpymm->time; goto NNO27; Ny5Xe: $CGIOU = $lpymm->bindings; goto oSnfm; GtZ1v: $fxyYQ = $lpymm->sql; goto Ny5Xe; NNO27: } self::$queryCountPerRequestSqls[] = array('sql' => $fxyYQ, 'bindings' => $CGIOU); if ($ANM3E > config('modstart.trackLongSqlThreshold', 5000)) { Log::warning("LONG_SQL {$ANM3E}ms, {$fxyYQ}, " . ArrayUtil::serializeForLog($CGIOU)); } }); } catch (\Exception $Y5fnH) { } goto L0eZx; XKDJt: self::$queryCountPerRequest = 0; goto viAxY; L0eZx: } public static function getQueryCountPerRequest() { return self::$queryCountPerRequest; } public static function getQueryCountPerRequestSqls() { foreach (self::$queryCountPerRequestSqls as $VJ5vg => $VFelt) { if (is_array($VFelt)) { $CGIOU = ArrayUtil::serializeForLog($VFelt['bindings']); self::$queryCountPerRequestSqls[$VJ5vg] = $VFelt['sql'] . ', ' . $CGIOU; } } return self::$queryCountPerRequestSqls; } }