<?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 vihDp; KI9lL: return !empty(self::$reportAddress); goto edRIA; vihDp: if (!defined('LARAVEL_START')) { return false; } goto wtmxj; wtmxj: if (!self::$inited) { self::$reportAddress = config('modstart.statisticServer', null); self::$inited = true; } goto KI9lL; edRIA: } public static function init() { goto RXOtz; RXOtz: if (!self::isEnable()) { return; } goto HwlYa; HwlYa: $KIbLj = 'kernel.handled'; goto B0POv; qnDar: Event::listen($KIbLj, function ($mpXGF = null, $CqM8X = null) use($KIbLj) { $U5_Oe = $mpXGF; if ($KIbLj == 'kernel.handled') { } else { $U5_Oe = $mpXGF->request; $CqM8X = $mpXGF->response; } $aoDgD = round((microtime(true) - LARAVEL_START) * 1000, 2); $VzVt9 = $U5_Oe->url(); $HkVnj = $U5_Oe->method(); $i98uu = Route::currentRouteAction(); $a1F4H = \ModStart\Core\Input\Request::domain(); self::tick($a1F4H, "{$HkVnj}." . $i98uu, $aoDgD); }); goto fNG6B; B0POv: if (class_exists('Illuminate\\Foundation\\Http\\Events\\RequestHandled')) { $KIbLj = 'Illuminate\\Foundation\\Http\\Events\\RequestHandled'; } goto qnDar; fNG6B: } public static function tickStart($CiBrR, $eBCLS) { if (!self::isEnable()) { return; } return self::$timeMap[$CiBrR][$eBCLS] = microtime(true); } public static function tickEnd($CiBrR, $eBCLS, $dwTdX = true, $pXRGe = 0, $UVkAh = null) { goto UgL00; hepwg: if (isset(self::$timeMap[$CiBrR][$eBCLS]) && self::$timeMap[$CiBrR][$eBCLS] > 0) { $uVir5 = self::$timeMap[$CiBrR][$eBCLS]; self::$timeMap[$CiBrR][$eBCLS] = 0; } else { $uVir5 = microtime(true); } goto t6513; t6513: self::send($CiBrR, $eBCLS, round((microtime(true) - $uVir5) * 1000, 2), $dwTdX, $pXRGe, $UVkAh); goto f6Ulp; UgL00: if (!self::isEnable()) { return; } goto hepwg; f6Ulp: } public static function tick($CiBrR, $eBCLS, $b4chE, $dwTdX = true, $pXRGe = 0, $UVkAh = null) { if (!self::isEnable()) { return; } self::send($CiBrR, $eBCLS, round($b4chE, 2), $dwTdX, $pXRGe, $UVkAh); } private static function send($CiBrR, $eBCLS, $R0kvU, $dwTdX, $pXRGe, $UVkAh) { try { $kGguB = self::encode($CiBrR, $eBCLS, $R0kvU, $dwTdX, $pXRGe, $UVkAh); if (extension_loaded('swoole')) { goto qbTPD; eO5Z3: self::$client = null; goto c6ell; einq_: self::$client->send($kGguB); goto rLMG0; qbTPD: if (!self::$client || !self::$client->isConnected()) { goto i25qV; botiS: list($WrX3L, $gMe2K) = explode(':', self::$reportAddress); goto huY6g; huY6g: self::$client->connect($WrX3L, $gMe2K); goto p_Xdu; i25qV: self::$client = new \swoole_client(SWOOLE_UDP); goto botiS; p_Xdu: } goto einq_; rLMG0: self::$client->close(); goto eO5Z3; c6ell: } else { goto KUFZ0; dt2m6: $uG6hJ = stream_socket_client('udp://' . self::$reportAddress, $OJO7u, $NhY52, $WO3gU); goto e6qBP; Tv3D5: stream_socket_sendto($uG6hJ, $kGguB); goto ACawc; e6qBP: if (!$uG6hJ) { return; } goto vbjg8; KUFZ0: $WO3gU = null; goto dt2m6; vbjg8: stream_set_timeout($uG6hJ, $WO3gU); goto Tv3D5; ACawc: } } catch (\Exception $xpJqz) { Log::error('MS.StatisticMonitor.Error -> ' . $xpJqz->getMessage()); } } private static function encode($CiBrR, $eBCLS, $R0kvU, $dwTdX, $pXRGe = 0, $UVkAh = '') { goto LK9Jd; JtPiJ: return $CI65w; goto mb_5F; LK9Jd: $SjN8A = array('module' => $CiBrR, 'group' => $eBCLS, 'cost' => $R0kvU, 'success' => $dwTdX, 'time' => time(), 'code' => $pXRGe, 'msg' => $UVkAh); goto pHAj3; pHAj3: $cgHv6 = json_encode($SjN8A); goto DTsrK; DTsrK: $CI65w = pack('N', strlen($cgHv6)) . $cgHv6; goto JtPiJ; mb_5F: } }