<?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 APDcZ; j2gyA: return !empty(self::$reportAddress); goto Pe2QS; Jb2Wf: if (!self::$inited) { self::$reportAddress = config('modstart.statisticServer', null); self::$inited = true; } goto j2gyA; APDcZ: if (!defined('LARAVEL_START')) { return false; } goto Jb2Wf; Pe2QS: } public static function init() { goto DTLEw; iaQCF: Event::listen($QDFT2, function ($iPBEV = null, $aziFu = null) use($QDFT2) { $Kv_Mp = $iPBEV; if ($QDFT2 == 'kernel.handled') { } else { $Kv_Mp = $iPBEV->request; $aziFu = $iPBEV->response; } $EjkFa = round((microtime(true) - LARAVEL_START) * 1000, 2); $MiLaY = $Kv_Mp->url(); $UVOMF = $Kv_Mp->method(); $JfLuA = Route::currentRouteAction(); $keY2T = \ModStart\Core\Input\Request::domain(); self::tick($keY2T, "{$UVOMF}." . $JfLuA, $EjkFa); }); goto BGWSQ; UPdfH: if (class_exists('Illuminate\\Foundation\\Http\\Events\\RequestHandled')) { $QDFT2 = 'Illuminate\\Foundation\\Http\\Events\\RequestHandled'; } goto iaQCF; iaQ6s: $QDFT2 = 'kernel.handled'; goto UPdfH; DTLEw: if (!self::isEnable()) { return; } goto iaQ6s; BGWSQ: } public static function tickStart($JHuzz, $o12RE) { if (!self::isEnable()) { return; } return self::$timeMap[$JHuzz][$o12RE] = microtime(true); } public static function tickEnd($JHuzz, $o12RE, $L8Uh3 = true, $rL76x = 0, $wx435 = null) { goto st32i; omYoB: if (isset(self::$timeMap[$JHuzz][$o12RE]) && self::$timeMap[$JHuzz][$o12RE] > 0) { $H2MJS = self::$timeMap[$JHuzz][$o12RE]; self::$timeMap[$JHuzz][$o12RE] = 0; } else { $H2MJS = microtime(true); } goto OfO3j; OfO3j: self::send($JHuzz, $o12RE, round((microtime(true) - $H2MJS) * 1000, 2), $L8Uh3, $rL76x, $wx435); goto pyYLV; st32i: if (!self::isEnable()) { return; } goto omYoB; pyYLV: } public static function tick($JHuzz, $o12RE, $o6YZX, $L8Uh3 = true, $rL76x = 0, $wx435 = null) { if (!self::isEnable()) { return; } self::send($JHuzz, $o12RE, round($o6YZX, 2), $L8Uh3, $rL76x, $wx435); } private static function send($JHuzz, $o12RE, $AyC5o, $L8Uh3, $rL76x, $wx435) { try { $gb2r1 = self::encode($JHuzz, $o12RE, $AyC5o, $L8Uh3, $rL76x, $wx435); if (extension_loaded('swoole')) { goto Agd6u; bSw5S: self::$client = null; goto T9ReE; Lj7rN: self::$client->send($gb2r1); goto JcSW2; Agd6u: if (!self::$client || !self::$client->isConnected()) { goto x8Klg; x8Klg: self::$client = new \swoole_client(SWOOLE_UDP); goto IdRhJ; lZsbQ: self::$client->connect($L6lVN, $wwaH0); goto JlWSh; IdRhJ: list($L6lVN, $wwaH0) = explode(':', self::$reportAddress); goto lZsbQ; JlWSh: } goto Lj7rN; JcSW2: self::$client->close(); goto bSw5S; T9ReE: } else { goto doKHf; q2vyo: stream_socket_sendto($qvJxT, $gb2r1); goto rE2Xi; hZ_pE: stream_set_timeout($qvJxT, $PmvMF); goto q2vyo; yLQXQ: $qvJxT = stream_socket_client('udp://' . self::$reportAddress, $tIf7_, $Ji3ae, $PmvMF); goto kNG12; kNG12: if (!$qvJxT) { return; } goto hZ_pE; doKHf: $PmvMF = null; goto yLQXQ; rE2Xi: } } catch (\Exception $Sgh1N) { Log::error('MS.StatisticMonitor.Error -> ' . $Sgh1N->getMessage()); } } private static function encode($JHuzz, $o12RE, $AyC5o, $L8Uh3, $rL76x = 0, $wx435 = '') { goto nc2Z4; gvgVu: $CzxDH = SerializeUtil::jsonEncode($dTnlu); goto bOr5N; NZuTy: return $YL3OY; goto JP5uv; bOr5N: $YL3OY = pack('N', strlen($CzxDH)) . $CzxDH; goto NZuTy; nc2Z4: $dTnlu = array('module' => $JHuzz, 'group' => $o12RE, 'cost' => $AyC5o, 'success' => $L8Uh3, 'time' => time(), 'code' => $rL76x, 'msg' => $wx435); goto gvgVu; JP5uv: } }