<?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; use ModStart\Core\Util\SerializeUtil; class StatisticMonitor { protected static $timeMap = array(); protected static $client = null; private static $inited = false; private static $reportAddress = null; public static function isEnable() { goto bbfuf; m9v4d: if (!self::$inited) { self::$reportAddress = config('modstart.statisticServer', null); self::$inited = true; } goto kciBn; kciBn: return !empty(self::$reportAddress); goto qgmfi; bbfuf: if (!defined('LARAVEL_START')) { return false; } goto m9v4d; qgmfi: } public static function init() { goto KROIM; SGLQ5: if (class_exists('Illuminate\\Foundation\\Http\\Events\\RequestHandled')) { $Vpwev = 'Illuminate\\Foundation\\Http\\Events\\RequestHandled'; } goto BC8Qi; CXjQu: $Vpwev = 'kernel.handled'; goto SGLQ5; BC8Qi: Event::listen($Vpwev, function ($pGa3o = null, $FqOmX = null) use($Vpwev) { $hoJyG = $pGa3o; if ($Vpwev == 'kernel.handled') { } else { $hoJyG = $pGa3o->request; $FqOmX = $pGa3o->response; } $vQlXM = round((microtime(true) - LARAVEL_START) * 1000, 2); $ik1Qg = $hoJyG->url(); $pK00s = $hoJyG->method(); $ziOie = Route::currentRouteAction(); $BlTXG = \ModStart\Core\Input\Request::domain(); self::tick($BlTXG, "{$pK00s}." . $ziOie, $vQlXM); }); goto h0XGd; KROIM: if (!self::isEnable()) { return; } goto CXjQu; h0XGd: } public static function tickStart($tUxPr, $F0_Ro) { if (!self::isEnable()) { return; } return self::$timeMap[$tUxPr][$F0_Ro] = microtime(true); } public static function tickEnd($tUxPr, $F0_Ro, $Y8lNo = true, $Urlj7 = 0, $jspW5 = null) { goto gIwCl; YAJto: if (isset(self::$timeMap[$tUxPr][$F0_Ro]) && self::$timeMap[$tUxPr][$F0_Ro] > 0) { $t9lHz = self::$timeMap[$tUxPr][$F0_Ro]; self::$timeMap[$tUxPr][$F0_Ro] = 0; } else { $t9lHz = microtime(true); } goto vCcVL; gIwCl: if (!self::isEnable()) { return; } goto YAJto; vCcVL: self::send($tUxPr, $F0_Ro, round((microtime(true) - $t9lHz) * 1000, 2), $Y8lNo, $Urlj7, $jspW5); goto s08De; s08De: } public static function tick($tUxPr, $F0_Ro, $t3cpK, $Y8lNo = true, $Urlj7 = 0, $jspW5 = null) { if (!self::isEnable()) { return; } self::send($tUxPr, $F0_Ro, round($t3cpK, 2), $Y8lNo, $Urlj7, $jspW5); } private static function send($tUxPr, $F0_Ro, $rB0QU, $Y8lNo, $Urlj7, $jspW5) { try { $kCPHG = self::encode($tUxPr, $F0_Ro, $rB0QU, $Y8lNo, $Urlj7, $jspW5); if (extension_loaded('swoole')) { goto ejbDj; g1adc: self::$client->send($kCPHG); goto jNPLf; jNPLf: self::$client->close(); goto I6n_t; I6n_t: self::$client = null; goto fCEN9; ejbDj: if (!self::$client || !self::$client->isConnected()) { goto sCw9d; tg8mJ: list($flpew, $O5bLV) = explode(':', self::$reportAddress); goto SWsmj; SWsmj: self::$client->connect($flpew, $O5bLV); goto jsQvE; sCw9d: self::$client = new \swoole_client(SWOOLE_UDP); goto tg8mJ; jsQvE: } goto g1adc; fCEN9: } else { goto yCUaG; RwIZY: $D1rjc = stream_socket_client('udp://' . self::$reportAddress, $is3Ag, $vPhrc, $Cq6fQ); goto eJwDE; XxlIY: stream_socket_sendto($D1rjc, $kCPHG); goto t8rTM; yCUaG: $Cq6fQ = null; goto RwIZY; SkOJo: stream_set_timeout($D1rjc, $Cq6fQ); goto XxlIY; eJwDE: if (!$D1rjc) { return; } goto SkOJo; t8rTM: } } catch (\Exception $Xlb8r) { Log::error('MS.StatisticMonitor.Error -> ' . $Xlb8r->getMessage()); } } private static function encode($tUxPr, $F0_Ro, $rB0QU, $Y8lNo, $Urlj7 = 0, $jspW5 = '') { goto XyVqW; XyVqW: $zvN10 = array('module' => $tUxPr, 'group' => $F0_Ro, 'cost' => $rB0QU, 'success' => $Y8lNo, 'time' => time(), 'code' => $Urlj7, 'msg' => $jspW5); goto CbQWW; yxo7D: $suHuH = pack('N', strlen($W8D7a)) . $W8D7a; goto q_qWJ; CbQWW: $W8D7a = SerializeUtil::jsonEncode($zvN10); goto yxo7D; q_qWJ: return $suHuH; goto KXJdy; KXJdy: } }