<?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 ReuII; UyscE: try { DB::listen(function ($hAzJ1, $YpdOu = null, $aoDgD = null, $mubZv = null) { self::$queryCountPerRequest++; $FgJEu = $hAzJ1; if (method_exists(\ModStart\ModStart::class, 'env') && \ModStart\ModStart::env() == 'laravel9') { goto SbKa_; MgQ7z: $YpdOu = $hAzJ1->bindings; goto AgfZE; AgfZE: $aoDgD = $hAzJ1->time; goto MSyPt; SbKa_: $FgJEu = $hAzJ1->sql; goto MgQ7z; MSyPt: } self::$queryCountPerRequestSqls[] = array('sql' => $FgJEu, 'bindings' => $YpdOu); if ($aoDgD > config('modstart.trackLongSqlThreshold', 5000)) { Log::warning("LONG_SQL {$aoDgD}ms, {$FgJEu}, " . ArrayUtil::serializeForLog($YpdOu)); } }); } catch (\Exception $xpJqz) { } goto k3cpi; ciCYW: self::$queryCountPerRequest = 0; goto SaL36; ReuII: if (!config('modstart.trackPerformance', false)) { return; } goto ciCYW; SaL36: self::$queryCountPerRequestSqls = array(); goto UyscE; k3cpi: } public static function getQueryCountPerRequest() { return self::$queryCountPerRequest; } public static function getQueryCountPerRequestSqls() { foreach (self::$queryCountPerRequestSqls as $UCcmA => $uTz0e) { if (is_array($uTz0e)) { $YpdOu = ArrayUtil::serializeForLog($uTz0e['bindings']); self::$queryCountPerRequestSqls[$UCcmA] = $uTz0e['sql'] . ', ' . $YpdOu; } } return self::$queryCountPerRequestSqls; } }