<?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 YOmfk; AeyJS: self::$queryCountPerRequestSqls = array(); goto MUxHq; rQBnK: self::$queryCountPerRequest = 0; goto AeyJS; MUxHq: try { DB::listen(function ($LBO09, $XmLq3 = null, $vQlXM = null, $t_uel = null) { self::$queryCountPerRequest++; $ZjqJz = $LBO09; if (method_exists(\ModStart\ModStart::class, 'env') && \ModStart\ModStart::env() == 'laravel9') { goto YwPLj; fGLxi: $vQlXM = $LBO09->time; goto VbtO1; jHnBD: $XmLq3 = $LBO09->bindings; goto fGLxi; YwPLj: $ZjqJz = $LBO09->sql; goto jHnBD; VbtO1: } self::$queryCountPerRequestSqls[] = array('sql' => $ZjqJz, 'bindings' => $XmLq3); if ($vQlXM > config('modstart.trackLongSqlThreshold', 5000)) { Log::warning("LONG_SQL {$vQlXM}ms, {$ZjqJz}, " . ArrayUtil::serializeForLog($XmLq3)); } }); } catch (\Exception $Xlb8r) { } goto JQlF3; YOmfk: if (!config('modstart.trackPerformance', false)) { return; } goto rQBnK; JQlF3: } public static function getQueryCountPerRequest() { return self::$queryCountPerRequest; } public static function getQueryCountPerRequestSqls() { foreach (self::$queryCountPerRequestSqls as $kM8qX => $Xz28r) { if (is_array($Xz28r)) { $XmLq3 = ArrayUtil::serializeForLog($Xz28r['bindings']); self::$queryCountPerRequestSqls[$kM8qX] = $Xz28r['sql'] . ', ' . $XmLq3; } } return self::$queryCountPerRequestSqls; } }