<?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 vIuAO; vIuAO: if (!defined('LARAVEL_START')) { return false; } goto e1XIB; p1i5m: return !empty(self::$reportAddress); goto pITPa; e1XIB: if (!self::$inited) { self::$reportAddress = config('modstart.statisticServer', null); self::$inited = true; } goto p1i5m; pITPa: } public static function init() { goto RD4YI; N5WRN: if (class_exists('Illuminate\\Foundation\\Http\\Events\\RequestHandled')) { $FK2EG = 'Illuminate\\Foundation\\Http\\Events\\RequestHandled'; } goto orXcx; mIrSU: $FK2EG = 'kernel.handled'; goto N5WRN; orXcx: Event::listen($FK2EG, function ($T9CQQ = null, $Lq983 = null) use($FK2EG) { $RDnT0 = $T9CQQ; if ($FK2EG == 'kernel.handled') { } else { $RDnT0 = $T9CQQ->request; $Lq983 = $T9CQQ->response; } $Zco5P = round((microtime(true) - LARAVEL_START) * 1000, 2); $XVqXz = $RDnT0->url(); $eNE35 = $RDnT0->method(); $UvPUF = Route::currentRouteAction(); $ft_KC = \ModStart\Core\Input\Request::domain(); self::tick($ft_KC, "{$eNE35}." . $UvPUF, $Zco5P); }); goto KHpT8; RD4YI: if (!self::isEnable()) { return; } goto mIrSU; KHpT8: } public static function tickStart($uacrl, $ky_TL) { if (!self::isEnable()) { return; } return self::$timeMap[$uacrl][$ky_TL] = microtime(true); } public static function tickEnd($uacrl, $ky_TL, $m4dTK = true, $vq5E2 = 0, $x2rrW = null) { goto OmTqV; OmTqV: if (!self::isEnable()) { return; } goto YRE8O; YRE8O: if (isset(self::$timeMap[$uacrl][$ky_TL]) && self::$timeMap[$uacrl][$ky_TL] > 0) { $Io7GI = self::$timeMap[$uacrl][$ky_TL]; self::$timeMap[$uacrl][$ky_TL] = 0; } else { $Io7GI = microtime(true); } goto iTk6c; iTk6c: self::send($uacrl, $ky_TL, round((microtime(true) - $Io7GI) * 1000, 2), $m4dTK, $vq5E2, $x2rrW); goto weNO9; weNO9: } public static function tick($uacrl, $ky_TL, $rl_Gp, $m4dTK = true, $vq5E2 = 0, $x2rrW = null) { if (!self::isEnable()) { return; } self::send($uacrl, $ky_TL, round($rl_Gp, 2), $m4dTK, $vq5E2, $x2rrW); } private static function send($uacrl, $ky_TL, $Tko1m, $m4dTK, $vq5E2, $x2rrW) { try { $aoOe7 = self::encode($uacrl, $ky_TL, $Tko1m, $m4dTK, $vq5E2, $x2rrW); if (extension_loaded('swoole')) { goto bgOvP; e8YTI: self::$client->send($aoOe7); goto d0AO2; ALORI: self::$client = null; goto CZ5zn; d0AO2: self::$client->close(); goto ALORI; bgOvP: if (!self::$client || !self::$client->isConnected()) { goto AiGDn; fa76b: self::$client->connect($h4mnJ, $GfvPj); goto NUM1N; X7yj3: list($h4mnJ, $GfvPj) = explode(':', self::$reportAddress); goto fa76b; AiGDn: self::$client = new \swoole_client(SWOOLE_UDP); goto X7yj3; NUM1N: } goto e8YTI; CZ5zn: } else { goto zs6O3; hQlBI: stream_socket_sendto($RJZQF, $aoOe7); goto Q2m4X; eRJTU: $RJZQF = stream_socket_client('udp://' . self::$reportAddress, $BcPTh, $K5EN7, $dUHzU); goto Q0jMs; qAibs: stream_set_timeout($RJZQF, $dUHzU); goto hQlBI; Q0jMs: if (!$RJZQF) { return; } goto qAibs; zs6O3: $dUHzU = null; goto eRJTU; Q2m4X: } } catch (\Exception $GrUf4) { Log::error('MS.StatisticMonitor.Error -> ' . $GrUf4->getMessage()); } } private static function encode($uacrl, $ky_TL, $Tko1m, $m4dTK, $vq5E2 = 0, $x2rrW = '') { goto XONiO; OcqG1: $EsNA0 = pack('N', strlen($HrIWB)) . $HrIWB; goto oF1XX; XONiO: $IaeCl = array('module' => $uacrl, 'group' => $ky_TL, 'cost' => $Tko1m, 'success' => $m4dTK, 'time' => time(), 'code' => $vq5E2, 'msg' => $x2rrW); goto S0wBH; oF1XX: return $EsNA0; goto GNw8W; S0wBH: $HrIWB = json_encode($IaeCl); goto OcqG1; GNw8W: } }