/** * 上报统计数据 * * @param string $module * @param string $interface * @param bool $success * @param int $code * @param string $msg * @param string $report_address * @return boolean */ public static function report($module, $interface, $success, $code, $msg, $report_address = '') { $report_address = $report_address ? $report_address : '127.0.0.1:55656'; if (isset(self::$timeMap[$module][$interface]) && self::$timeMap[$module][$interface] > 0) { $time_start = self::$timeMap[$module][$interface]; self::$timeMap[$module][$interface] = 0; } else { if (isset(self::$timeMap['']['']) && self::$timeMap[''][''] > 0) { $time_start = self::$timeMap['']['']; self::$timeMap[''][''] = 0; } else { $time_start = microtime(true); } } $cost_time = microtime(true) - $time_start; $bin_data = Protocol::encode($module, $interface, $cost_time, $success, $code, $msg); if (extension_loaded('swoole')) { if (!self::$client || !self::$client->isConnected()) { self::$client = new swoole_client(SWOOLE_TCP, SWOOLE_SOCK_SYNC); list($ip, $port) = explode(':', $report_address); self::$client->connect($ip, $port); } self::$client->send($bin_data); self::$client->close(); self::$client = null; } else { return self::sendData($report_address, $bin_data); } }