<?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 P3d_B; P3d_B: if (!config('modstart.trackPerformance', false)) { return; } goto eQdlB; eQdlB: self::$queryCountPerRequest = 0; goto EJ58E; HCUr0: try { DB::listen(function ($sFfhd, $EKqSM = null, $sEFWu = null, $Hckbl = null) { self::$queryCountPerRequest++; $ATIJP = $sFfhd; if (method_exists(\ModStart\ModStart::class, 'env') && \ModStart\ModStart::env() == 'laravel9') { goto ob9pB; oD0Bx: $EKqSM = $sFfhd->bindings; goto ASNMl; ob9pB: $ATIJP = $sFfhd->sql; goto oD0Bx; ASNMl: $sEFWu = $sFfhd->time; goto VgCtd; VgCtd: } self::$queryCountPerRequestSqls[] = array('sql' => $ATIJP, 'bindings' => $EKqSM); if ($sEFWu > config('modstart.trackLongSqlThreshold', 5000)) { Log::warning("LONG_SQL {$sEFWu}ms, {$ATIJP}, " . ArrayUtil::serializeForLog($EKqSM)); } }); } catch (\Exception $WVwSN) { } goto vqSX3; EJ58E: self::$queryCountPerRequestSqls = array(); goto HCUr0; vqSX3: } public static function getQueryCountPerRequest() { return self::$queryCountPerRequest; } public static function getQueryCountPerRequestSqls() { foreach (self::$queryCountPerRequestSqls as $MqJHJ => $F6Fus) { if (is_array($F6Fus)) { $EKqSM = ArrayUtil::serializeForLog($F6Fus['bindings']); self::$queryCountPerRequestSqls[$MqJHJ] = $F6Fus['sql'] . ', ' . $EKqSM; } } return self::$queryCountPerRequestSqls; } }