<?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 DmN6v; DmN6v: if (!config('modstart.trackPerformance', false)) { return; } goto jQLjW; jQLjW: self::$queryCountPerRequest = 0; goto BwdVB; BwdVB: self::$queryCountPerRequestSqls = array(); goto iIrtu; iIrtu: try { DB::listen(function ($xaAIg, $RE5ig = null, $Zco5P = null, $d5h2Q = null) { self::$queryCountPerRequest++; $Ry27s = $xaAIg; if (method_exists(\ModStart\ModStart::class, 'env') && \ModStart\ModStart::env() == 'laravel9') { goto VWgVC; eCTfF: $RE5ig = $xaAIg->bindings; goto jKHV2; VWgVC: $Ry27s = $xaAIg->sql; goto eCTfF; jKHV2: $Zco5P = $xaAIg->time; goto PApsb; PApsb: } self::$queryCountPerRequestSqls[] = array('sql' => $Ry27s, 'bindings' => $RE5ig); if ($Zco5P > config('modstart.trackLongSqlThreshold', 5000)) { Log::warning("LONG_SQL {$Zco5P}ms, {$Ry27s}, " . ArrayUtil::serializeForLog($RE5ig)); } }); } catch (\Exception $GrUf4) { } goto QQCgF; QQCgF: } public static function getQueryCountPerRequest() { return self::$queryCountPerRequest; } public static function getQueryCountPerRequestSqls() { foreach (self::$queryCountPerRequestSqls as $JhHfm => $JiRHR) { if (is_array($JiRHR)) { $RE5ig = ArrayUtil::serializeForLog($JiRHR['bindings']); self::$queryCountPerRequestSqls[$JhHfm] = $JiRHR['sql'] . ', ' . $RE5ig; } } return self::$queryCountPerRequestSqls; } }