<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Core\Monitor; use Illuminate\Http\Request; use Illuminate\Http\Response; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Route; class StatisticMonitor { protected static $timeMap = array(); protected static $client = null; private static $inited = false; private static $reportAddress = null; public static function isEnable() { goto g431P; O3ALi: if (!self::$inited) { self::$reportAddress = config('modstart.statisticServer', null); self::$inited = true; } goto i5pOy; g431P: if (!defined('LARAVEL_START')) { return false; } goto O3ALi; i5pOy: return !empty(self::$reportAddress); goto Qgnnl; Qgnnl: } public static function init() { goto UH158; tUreu: Event::listen($YDxDq, function ($K0adC = null, $i1_1k = null) use($YDxDq) { $MRMCA = $K0adC; if ($YDxDq == 'kernel.handled') { } else { $MRMCA = $K0adC->request; $i1_1k = $K0adC->response; } $gmNPm = round((microtime(true) - LARAVEL_START) * 1000, 2); $xIfit = $MRMCA->url(); $JHYOH = $MRMCA->method(); $H8T3G = Route::currentRouteAction(); $xk3Sl = \ModStart\Core\Input\Request::domain(); self::tick($xk3Sl, "{$JHYOH}." . $H8T3G, $gmNPm); }); goto PZtmV; UH158: if (!self::isEnable()) { return; } goto KraUf; KraUf: $YDxDq = 'kernel.handled'; goto nsHOr; nsHOr: if (class_exists('Illuminate\\Foundation\\Http\\Events\\RequestHandled')) { $YDxDq = 'Illuminate\\Foundation\\Http\\Events\\RequestHandled'; } goto tUreu; PZtmV: } public static function tickStart($GVDx3, $RpVCk) { if (!self::isEnable()) { return; } return self::$timeMap[$GVDx3][$RpVCk] = microtime(true); } public static function tickEnd($GVDx3, $RpVCk, $Qgrk_ = true, $vu_fe = 0, $XKiRP = null) { goto YiJSE; Wjcq1: self::send($GVDx3, $RpVCk, round((microtime(true) - $wh9GM) * 1000, 2), $Qgrk_, $vu_fe, $XKiRP); goto FOOYO; wV2tM: if (isset(self::$timeMap[$GVDx3][$RpVCk]) && self::$timeMap[$GVDx3][$RpVCk] > 0) { $wh9GM = self::$timeMap[$GVDx3][$RpVCk]; self::$timeMap[$GVDx3][$RpVCk] = 0; } else { $wh9GM = microtime(true); } goto Wjcq1; YiJSE: if (!self::isEnable()) { return; } goto wV2tM; FOOYO: } public static function tick($GVDx3, $RpVCk, $lbxdw, $Qgrk_ = true, $vu_fe = 0, $XKiRP = null) { if (!self::isEnable()) { return; } self::send($GVDx3, $RpVCk, round($lbxdw, 2), $Qgrk_, $vu_fe, $XKiRP); } private static function send($GVDx3, $RpVCk, $PYNcV, $Qgrk_, $vu_fe, $XKiRP) { try { $JpH9C = self::encode($GVDx3, $RpVCk, $PYNcV, $Qgrk_, $vu_fe, $XKiRP); if (extension_loaded('swoole')) { goto YkvCj; YkvCj: if (!self::$client || !self::$client->isConnected()) { goto Ioih2; yGh9S: self::$client->connect($RsqtJ, $d1DGl); goto rAvnC; nQeLK: list($RsqtJ, $d1DGl) = explode(':', self::$reportAddress); goto yGh9S; Ioih2: self::$client = new \swoole_client(SWOOLE_UDP); goto nQeLK; rAvnC: } goto VjvJW; m2YV0: self::$client->close(); goto zXvLk; zXvLk: self::$client = null; goto GIISL; VjvJW: self::$client->send($JpH9C); goto m2YV0; GIISL: } else { goto iLpLE; Pxg0y: stream_socket_sendto($FIJpj, $JpH9C); goto Aqix0; j6vyn: stream_set_timeout($FIJpj, $gtCgf); goto Pxg0y; iLpLE: $gtCgf = null; goto memXS; bLfod: if (!$FIJpj) { return; } goto j6vyn; memXS: $FIJpj = stream_socket_client('udp://' . self::$reportAddress, $mm2T_, $GZItr, $gtCgf); goto bLfod; Aqix0: } } catch (\Exception $SXS9c) { Log::error('MS.StatisticMonitor.Error -> ' . $SXS9c->getMessage()); } } private static function encode($GVDx3, $RpVCk, $PYNcV, $Qgrk_, $vu_fe = 0, $XKiRP = '') { goto UA1Sw; Ns1_K: $i7B59 = json_encode($EdQjV); goto MNW0d; UA1Sw: $EdQjV = array('module' => $GVDx3, 'group' => $RpVCk, 'cost' => $PYNcV, 'success' => $Qgrk_, 'time' => time(), 'code' => $vu_fe, 'msg' => $XKiRP); goto Ns1_K; MNW0d: $hmMx0 = pack('N', strlen($i7B59)) . $i7B59; goto NNC2N; NNC2N: return $hmMx0; goto OiSdu; OiSdu: } }