<?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 dQrVW; Umxym: if (!self::$inited) { self::$reportAddress = config('modstart.statisticServer', null); self::$inited = true; } goto Sve1J; dQrVW: if (!defined('LARAVEL_START')) { return false; } goto Umxym; Sve1J: return !empty(self::$reportAddress); goto JEnN0; JEnN0: } public static function init() { goto t_Ky0; K20NO: if (class_exists('Illuminate\\Foundation\\Http\\Events\\RequestHandled')) { $OeByj = 'Illuminate\\Foundation\\Http\\Events\\RequestHandled'; } goto XWnwX; XWnwX: Event::listen($OeByj, function ($p4Rr6 = null, $YD5di = null) use($OeByj) { $fzeTQ = $p4Rr6; if ($OeByj == 'kernel.handled') { } else { $fzeTQ = $p4Rr6->request; $YD5di = $p4Rr6->response; } $CoZv2 = round((microtime(true) - LARAVEL_START) * 1000, 2); $tpgiq = $fzeTQ->url(); $fVu6a = $fzeTQ->method(); $wuAJG = Route::currentRouteAction(); $tYHk2 = \ModStart\Core\Input\Request::domain(); self::tick($tYHk2, "{$fVu6a}." . $wuAJG, $CoZv2); }); goto yj90O; t_Ky0: if (!self::isEnable()) { return; } goto d2dSl; d2dSl: $OeByj = 'kernel.handled'; goto K20NO; yj90O: } public static function tickStart($oXHYw, $ElG57) { if (!self::isEnable()) { return; } return self::$timeMap[$oXHYw][$ElG57] = microtime(true); } public static function tickEnd($oXHYw, $ElG57, $LpvCT = true, $lDWj3 = 0, $N0Z_W = null) { goto wdR4m; VP7Bc: if (isset(self::$timeMap[$oXHYw][$ElG57]) && self::$timeMap[$oXHYw][$ElG57] > 0) { $dcr_X = self::$timeMap[$oXHYw][$ElG57]; self::$timeMap[$oXHYw][$ElG57] = 0; } else { $dcr_X = microtime(true); } goto xEPje; wdR4m: if (!self::isEnable()) { return; } goto VP7Bc; xEPje: self::send($oXHYw, $ElG57, round((microtime(true) - $dcr_X) * 1000, 2), $LpvCT, $lDWj3, $N0Z_W); goto pWrxb; pWrxb: } public static function tick($oXHYw, $ElG57, $qp1ZW, $LpvCT = true, $lDWj3 = 0, $N0Z_W = null) { if (!self::isEnable()) { return; } self::send($oXHYw, $ElG57, round($qp1ZW, 2), $LpvCT, $lDWj3, $N0Z_W); } private static function send($oXHYw, $ElG57, $X1Td_, $LpvCT, $lDWj3, $N0Z_W) { try { $EP3N9 = self::encode($oXHYw, $ElG57, $X1Td_, $LpvCT, $lDWj3, $N0Z_W); if (extension_loaded('swoole')) { goto ktp4q; xzFrB: self::$client->send($EP3N9); goto U3rR1; U3rR1: self::$client->close(); goto odYAN; odYAN: self::$client = null; goto ONsKO; ktp4q: if (!self::$client || !self::$client->isConnected()) { goto T6N1N; z1rVV: self::$client->connect($TOxsO, $UuN_O); goto N92qB; Dmx4Z: list($TOxsO, $UuN_O) = explode(':', self::$reportAddress); goto z1rVV; T6N1N: self::$client = new \swoole_client(SWOOLE_UDP); goto Dmx4Z; N92qB: } goto xzFrB; ONsKO: } else { goto mtjeH; mtjeH: $Qm3dU = null; goto ANi1W; Hwz9h: stream_socket_sendto($P0zRm, $EP3N9); goto At_CD; jeWKz: stream_set_timeout($P0zRm, $Qm3dU); goto Hwz9h; ANi1W: $P0zRm = stream_socket_client('udp://' . self::$reportAddress, $uTgzg, $Mg_K4, $Qm3dU); goto nLrmQ; nLrmQ: if (!$P0zRm) { return; } goto jeWKz; At_CD: } } catch (\Exception $SwVsw) { Log::error('MS.StatisticMonitor.Error -> ' . $SwVsw->getMessage()); } } private static function encode($oXHYw, $ElG57, $X1Td_, $LpvCT, $lDWj3 = 0, $N0Z_W = '') { goto uNTDS; fcYG2: $WLl1X = SerializeUtil::jsonEncode($zonFp); goto A0Zrm; A0Zrm: $K0MbA = pack('N', strlen($WLl1X)) . $WLl1X; goto AP2P_; uNTDS: $zonFp = array('module' => $oXHYw, 'group' => $ElG57, 'cost' => $X1Td_, 'success' => $LpvCT, 'time' => time(), 'code' => $lDWj3, 'msg' => $N0Z_W); goto fcYG2; AP2P_: return $K0MbA; goto u14Il; u14Il: } }