<?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 Lh9KO; Lh9KO: if (!defined('LARAVEL_START')) { return false; } goto NokJR; NokJR: if (!self::$inited) { self::$reportAddress = config('modstart.statisticServer', null); self::$inited = true; } goto l0DtN; l0DtN: return !empty(self::$reportAddress); goto u0Fcd; u0Fcd: } public static function init() { goto VVHf3; Jbl4w: if (class_exists('Illuminate\\Foundation\\Http\\Events\\RequestHandled')) { $tv6TU = 'Illuminate\\Foundation\\Http\\Events\\RequestHandled'; } goto OcLoe; VVHf3: if (!self::isEnable()) { return; } goto qvKr5; qvKr5: $tv6TU = 'kernel.handled'; goto Jbl4w; OcLoe: Event::listen($tv6TU, function ($gQwRg = null, $mf4Oy = null) use($tv6TU) { $cSn43 = $gQwRg; if ($tv6TU == 'kernel.handled') { } else { $cSn43 = $gQwRg->request; $mf4Oy = $gQwRg->response; } $ANM3E = round((microtime(true) - LARAVEL_START) * 1000, 2); $YjgEW = $cSn43->url(); $HxDDI = $cSn43->method(); $nZRNd = Route::currentRouteAction(); $esWXv = \ModStart\Core\Input\Request::domain(); self::tick($esWXv, "{$HxDDI}." . $nZRNd, $ANM3E); }); goto t9_20; t9_20: } public static function tickStart($vbusR, $bg3WE) { if (!self::isEnable()) { return; } return self::$timeMap[$vbusR][$bg3WE] = microtime(true); } public static function tickEnd($vbusR, $bg3WE, $eL9Wo = true, $xIPHd = 0, $SzFqT = null) { goto bQw4n; bQw4n: if (!self::isEnable()) { return; } goto a1Hc0; cuO81: self::send($vbusR, $bg3WE, round((microtime(true) - $VW8wP) * 1000, 2), $eL9Wo, $xIPHd, $SzFqT); goto SyoVM; a1Hc0: if (isset(self::$timeMap[$vbusR][$bg3WE]) && self::$timeMap[$vbusR][$bg3WE] > 0) { $VW8wP = self::$timeMap[$vbusR][$bg3WE]; self::$timeMap[$vbusR][$bg3WE] = 0; } else { $VW8wP = microtime(true); } goto cuO81; SyoVM: } public static function tick($vbusR, $bg3WE, $jtqfI, $eL9Wo = true, $xIPHd = 0, $SzFqT = null) { if (!self::isEnable()) { return; } self::send($vbusR, $bg3WE, round($jtqfI, 2), $eL9Wo, $xIPHd, $SzFqT); } private static function send($vbusR, $bg3WE, $L31OQ, $eL9Wo, $xIPHd, $SzFqT) { try { $wVK3W = self::encode($vbusR, $bg3WE, $L31OQ, $eL9Wo, $xIPHd, $SzFqT); if (extension_loaded('swoole')) { goto K7k_S; Yx0BP: self::$client = null; goto k3NPO; uvetb: self::$client->send($wVK3W); goto xah6E; K7k_S: if (!self::$client || !self::$client->isConnected()) { goto rYf2J; N9wPf: list($RVEj2, $MmmiB) = explode(':', self::$reportAddress); goto Z4tu5; rYf2J: self::$client = new \swoole_client(SWOOLE_UDP); goto N9wPf; Z4tu5: self::$client->connect($RVEj2, $MmmiB); goto wU3Uo; wU3Uo: } goto uvetb; xah6E: self::$client->close(); goto Yx0BP; k3NPO: } else { goto BJod3; Jq9x8: stream_set_timeout($J3scy, $CG1sb); goto Pfnq_; Pfnq_: stream_socket_sendto($J3scy, $wVK3W); goto yDHBX; BJod3: $CG1sb = null; goto bRjSK; Qk0j7: if (!$J3scy) { return; } goto Jq9x8; bRjSK: $J3scy = stream_socket_client('udp://' . self::$reportAddress, $Jwfmg, $WzdGg, $CG1sb); goto Qk0j7; yDHBX: } } catch (\Exception $Y5fnH) { Log::error('MS.StatisticMonitor.Error -> ' . $Y5fnH->getMessage()); } } private static function encode($vbusR, $bg3WE, $L31OQ, $eL9Wo, $xIPHd = 0, $SzFqT = '') { goto tm2pr; uS8lj: return $NuHxl; goto P6imR; iqNM8: $NuHxl = pack('N', strlen($T5Bna)) . $T5Bna; goto uS8lj; FTGpN: $T5Bna = json_encode($OTBPk); goto iqNM8; tm2pr: $OTBPk = array('module' => $vbusR, 'group' => $bg3WE, 'cost' => $L31OQ, 'success' => $eL9Wo, 'time' => time(), 'code' => $xIPHd, 'msg' => $SzFqT); goto FTGpN; P6imR: } }