<?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 aJ9S1; aJ9S1: if (!defined('LARAVEL_START')) { return false; } goto jY3uZ; Zxc2M: return !empty(self::$reportAddress); goto K5OWu; jY3uZ: if (!self::$inited) { self::$reportAddress = config('modstart.statisticServer', null); self::$inited = true; } goto Zxc2M; K5OWu: } public static function init() { goto LF53l; LF53l: if (!self::isEnable()) { return; } goto UVCcw; UVCcw: $UP57w = 'kernel.handled'; goto krBOA; krBOA: if (class_exists('Illuminate\\Foundation\\Http\\Events\\RequestHandled')) { $UP57w = 'Illuminate\\Foundation\\Http\\Events\\RequestHandled'; } goto DkAhB; DkAhB: Event::listen($UP57w, function ($jBvVt = null, $HMP0x = null) use($UP57w) { $gSoa2 = $jBvVt; if ($UP57w == 'kernel.handled') { } else { $gSoa2 = $jBvVt->request; $HMP0x = $jBvVt->response; } $oWzL0 = round((microtime(true) - LARAVEL_START) * 1000, 2); $iERFh = $gSoa2->url(); $hiFdg = $gSoa2->method(); $FvLkj = Route::currentRouteAction(); $igVv7 = \ModStart\Core\Input\Request::domain(); self::tick($igVv7, "{$hiFdg}." . $FvLkj, $oWzL0); }); goto fBUj7; fBUj7: } public static function tickStart($satFX, $QCe7q) { if (!self::isEnable()) { return; } return self::$timeMap[$satFX][$QCe7q] = microtime(true); } public static function tickEnd($satFX, $QCe7q, $Xmy9N = true, $Zrxu_ = 0, $phm8V = null) { goto Rymp1; y5IZF: self::send($satFX, $QCe7q, round((microtime(true) - $GnkkS) * 1000, 2), $Xmy9N, $Zrxu_, $phm8V); goto v2l3D; Rymp1: if (!self::isEnable()) { return; } goto NIhBI; NIhBI: if (isset(self::$timeMap[$satFX][$QCe7q]) && self::$timeMap[$satFX][$QCe7q] > 0) { $GnkkS = self::$timeMap[$satFX][$QCe7q]; self::$timeMap[$satFX][$QCe7q] = 0; } else { $GnkkS = microtime(true); } goto y5IZF; v2l3D: } public static function tick($satFX, $QCe7q, $r4tIl, $Xmy9N = true, $Zrxu_ = 0, $phm8V = null) { if (!self::isEnable()) { return; } self::send($satFX, $QCe7q, round($r4tIl, 2), $Xmy9N, $Zrxu_, $phm8V); } private static function send($satFX, $QCe7q, $HR7yA, $Xmy9N, $Zrxu_, $phm8V) { try { $Svr32 = self::encode($satFX, $QCe7q, $HR7yA, $Xmy9N, $Zrxu_, $phm8V); if (extension_loaded('swoole')) { goto tGXg7; tGXg7: if (!self::$client || !self::$client->isConnected()) { goto i9_1R; i9_1R: self::$client = new \swoole_client(SWOOLE_UDP); goto b9Wvw; b9Wvw: list($aQyrc, $gfBUu) = explode(':', self::$reportAddress); goto jNdnp; jNdnp: self::$client->connect($aQyrc, $gfBUu); goto JS9O1; JS9O1: } goto s21vC; s21vC: self::$client->send($Svr32); goto BwHSt; BwHSt: self::$client->close(); goto XrUyI; XrUyI: self::$client = null; goto LpWK4; LpWK4: } else { goto mQTsf; F48cz: stream_socket_sendto($YlDGV, $Svr32); goto B0bnR; G2S7M: if (!$YlDGV) { return; } goto Ak4Ng; mQTsf: $t33Sv = null; goto oC1lm; oC1lm: $YlDGV = stream_socket_client('udp://' . self::$reportAddress, $yStEF, $xP8H6, $t33Sv); goto G2S7M; Ak4Ng: stream_set_timeout($YlDGV, $t33Sv); goto F48cz; B0bnR: } } catch (\Exception $tZVhb) { Log::error('MS.StatisticMonitor.Error -> ' . $tZVhb->getMessage()); } } private static function encode($satFX, $QCe7q, $HR7yA, $Xmy9N, $Zrxu_ = 0, $phm8V = '') { goto p6fJO; p6fJO: $Sj05q = array('module' => $satFX, 'group' => $QCe7q, 'cost' => $HR7yA, 'success' => $Xmy9N, 'time' => time(), 'code' => $Zrxu_, 'msg' => $phm8V); goto MX1ZA; Ckszn: $v2GHv = pack('N', strlen($jFNXP)) . $jFNXP; goto wrqdz; wrqdz: return $v2GHv; goto HEQN2; MX1ZA: $jFNXP = json_encode($Sj05q); goto Ckszn; HEQN2: } }