StatisticWorker.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. <?php
  2. require_once WORKERMAN_ROOT_DIR . 'man/Core/SocketWorker.php';
  3. /**
  4. *
  5. * @author walkor <worker-man@qq.com>
  6. */
  7. class StatisticWorker extends Man\Core\SocketWorker
  8. {
  9. /**
  10. * 最大日志buffer,大于这个值就写磁盘
  11. * @var integer
  12. */
  13. const MAX_LOG_BUFFER_SZIE = 1024000;
  14. /**
  15. * 多长时间写一次数据到磁盘
  16. * @var integer
  17. */
  18. const WRITE_PERIOD_LENGTH = 60;
  19. /**
  20. * 多长时间清理一次老的磁盘数据
  21. * @var integer
  22. */
  23. const CLEAR_PERIOD_LENGTH = 86400;
  24. /**
  25. * 数据多长时间过期
  26. * @var integer
  27. */
  28. const EXPIRED_TIME = 1296000;
  29. /**
  30. * 统计数据
  31. * ip=>modid=>interface=>['code'=>[xx=>count,xx=>count],'suc_cost_time'=>xx,'fail_cost_time'=>xx, 'suc_count'=>xx, 'fail_count'=>xx]
  32. * @var array
  33. */
  34. protected $statisticData = array();
  35. /**
  36. * 日志的buffer
  37. * @var string
  38. */
  39. protected $logBuffer = '';
  40. /**
  41. * 放统计数据的目录(相对于workerman/logs/)
  42. * @var string
  43. */
  44. protected $statisticDir = 'statistic/statistic/';
  45. /**
  46. * 存放统计日志的目录(相对于workerman/logs/)
  47. * @var string
  48. */
  49. protected $logDir = 'statistic/log/';
  50. /**
  51. * 提供统计查询的socket
  52. * @var resource
  53. */
  54. protected $providerSocket = null;
  55. /**
  56. * udp 默认全部接收完毕
  57. * @see Man\Core.SocketWorker::dealInput()
  58. */
  59. public function dealInput($recv_str)
  60. {
  61. return 0;
  62. }
  63. /**
  64. * 业务处理
  65. * @see Man\Core.SocketWorker::dealProcess()
  66. */
  67. public function dealProcess($recv_str)
  68. {
  69. // 如果是JSON协议,则是请求统计数据
  70. if($recv_str[0] === '{')
  71. {
  72. return $this->dealProvider($recv_str);
  73. }
  74. // 解码
  75. $unpack_data = StatisticProtocol::decode($recv_str);
  76. $module = $unpack_data['module'];
  77. $interface = $unpack_data['interface'];
  78. $cost_time = $unpack_data['cost_time'];
  79. $success = $unpack_data['success'];
  80. $time = $unpack_data['time'];
  81. $code = $unpack_data['code'];
  82. $msg = str_replace("\n", "<br>", $unpack_data['msg']);
  83. $ip = $this->getRemoteIp();
  84. // 模块接口统计
  85. $this->collectStatistics($module, $interface, $cost_time, $success, $ip, $code, $msg);
  86. // 全局统计
  87. $this->collectStatistics('WorkerMan', 'Statistics', $cost_time, $success, $ip, $code, $msg);
  88. // 失败记录日志
  89. if(!$success)
  90. {
  91. $this->logBuffer .= date('Y-m-d H:i:s',$time)."\t$ip\t$module::$interface\tcode:$code\tmsg:$msg\n";
  92. if(strlen($this->logBuffer) >= self::MAX_LOG_BUFFER_SZIE)
  93. {
  94. $this->writeLogToDisk();
  95. }
  96. }
  97. }
  98. /**
  99. * 收集统计数据
  100. * @param string $module
  101. * @param string $interface
  102. * @param float $cost_time
  103. * @param int $success
  104. * @param string $ip
  105. * @param int $code
  106. * @param string $msg
  107. * @return void
  108. */
  109. protected function collectStatistics($module, $interface , $cost_time, $success, $ip, $code, $msg)
  110. {
  111. // 统计相关信息
  112. if(!isset($this->statisticData[$ip]))
  113. {
  114. $this->statisticData[$ip] = array();
  115. }
  116. if(!isset($this->statisticData[$ip][$module]))
  117. {
  118. $this->statisticData[$ip][$module] = array();
  119. }
  120. if(!isset($this->statisticData[$ip][$module][$interface]))
  121. {
  122. $this->statisticData[$ip][$module][$interface] = array('code'=>array(), 'suc_cost_time'=>0, 'fail_cost_time'=>0, 'suc_count'=>0, 'fail_count'=>0);
  123. }
  124. if(!isset($this->statisticData[$ip][$module][$interface]['code'][$code]))
  125. {
  126. $this->statisticData[$ip][$module][$interface]['code'][$code] = 0;
  127. }
  128. $this->statisticData[$ip][$module][$interface]['code'][$code]++;
  129. if($success)
  130. {
  131. $this->statisticData[$ip][$module][$interface]['suc_cost_time'] += $cost_time;
  132. $this->statisticData[$ip][$module][$interface]['suc_count'] ++;
  133. }
  134. else
  135. {
  136. $this->statisticData[$ip][$module][$interface]['fail_cost_time'] += $cost_time;
  137. $this->statisticData[$ip][$module][$interface]['fail_count'] ++;
  138. }
  139. }
  140. /**
  141. * 将统计数据写入磁盘
  142. * @return void
  143. */
  144. public function writeStatisticsToDisk()
  145. {
  146. $time = time();
  147. // 循环将每个ip的统计数据写入磁盘
  148. foreach($this->statisticData as $ip => $mod_if_data)
  149. {
  150. foreach($mod_if_data as $module=>$items)
  151. {
  152. // 文件夹不存在则创建一个
  153. $file_dir = WORKERMAN_LOG_DIR . $this->statisticDir.$module;
  154. if(!is_dir($file_dir))
  155. {
  156. umask(0);
  157. mkdir($file_dir, 0777, true);
  158. }
  159. // 依次写入磁盘
  160. foreach($items as $interface=>$data)
  161. {
  162. file_put_contents($file_dir. "/{$interface}|".date('Y-m-d'), "$ip\t$time\t{$data['suc_count']}\t{$data['suc_cost_time']}\t{$data['fail_count']}\t{$data['fail_cost_time']}\t".json_encode($data['code'])."\n", FILE_APPEND | LOCK_EX);
  163. }
  164. }
  165. }
  166. // 清空统计
  167. $this->statisticData = array();
  168. }
  169. /**
  170. * 将日志数据写入磁盘
  171. * @return void
  172. */
  173. public function writeLogToDisk()
  174. {
  175. // 没有统计数据则返回
  176. if(empty($this->logBuffer))
  177. {
  178. return;
  179. }
  180. // 写入磁盘
  181. file_put_contents(WORKERMAN_LOG_DIR . $this->logDir . date('Y-m-d'), $this->logBuffer, FILE_APPEND | LOCK_EX);
  182. $this->logBuffer = '';
  183. }
  184. /**
  185. * 初始化
  186. * 统计目录检查
  187. * 初始化任务
  188. * @see Man\Core.SocketWorker::onStart()
  189. */
  190. protected function onStart()
  191. {
  192. // 初始化目录
  193. umask(0);
  194. $statistic_dir = WORKERMAN_LOG_DIR . $this->statisticDir;
  195. if(!is_dir($statistic_dir))
  196. {
  197. mkdir($statistic_dir, 0777, true);
  198. }
  199. $log_dir = WORKERMAN_LOG_DIR . $this->logDir;
  200. if(!is_dir($log_dir))
  201. {
  202. mkdir($log_dir, 0777, true);
  203. }
  204. // 初始化任务
  205. \Man\Core\Lib\Task::init($this->event);
  206. // 定时保存统计数据
  207. \Man\Core\Lib\Task::add(self::WRITE_PERIOD_LENGTH, array($this, 'writeStatisticsToDisk'));
  208. \Man\Core\Lib\Task::add(self::WRITE_PERIOD_LENGTH, array($this, 'writeLogToDisk'));
  209. // 定时清理不用的统计数据
  210. \Man\Core\Lib\Task::add(self::CLEAR_PERIOD_LENGTH, array($this, 'clearDisk'), array(WORKERMAN_LOG_DIR . $this->statisticDir, self::EXPIRED_TIME));
  211. \Man\Core\Lib\Task::add(self::CLEAR_PERIOD_LENGTH, array($this, 'clearDisk'), array(WORKERMAN_LOG_DIR . $this->logDir, self::EXPIRED_TIME));
  212. // 创建一个tcp监听,用来提供统计查询服务
  213. $this->providerSocket = stream_socket_server(\Man\Core\Lib\Config::get($this->workerName.'.provider_listen'));
  214. if($this->providerSocket)
  215. {
  216. $ret = $this->event->add($this->providerSocket, \Man\Core\Events\BaseEvent::EV_READ, array($this, 'accept'));
  217. }
  218. }
  219. /**
  220. * 进程停止时需要将数据写入磁盘
  221. * @see Man\Core.SocketWorker::onStop()
  222. */
  223. protected function onStop()
  224. {
  225. $this->writeLogToDisk();
  226. $this->writeStatisticsToDisk();
  227. }
  228. /**
  229. * 清除磁盘数据
  230. * @param string $file
  231. * @param int $exp_time
  232. */
  233. protected function clearDisk($file = null, $exp_time = 86400)
  234. {
  235. $time_now = time();
  236. if(is_file($file))
  237. {
  238. $mtime = filemtime($file);
  239. if(!$mtime)
  240. {
  241. $this->notice("filemtime $file fail");
  242. return;
  243. }
  244. if($time_now - $mtime > $exp_time)
  245. {
  246. unlink($file);
  247. }
  248. return;
  249. }
  250. foreach (glob($file."/*") as $file_name)
  251. {
  252. $this->clearDisk($file_name, $exp_time);
  253. }
  254. }
  255. /**
  256. * 处理请求统计
  257. * @param string $recv_str
  258. */
  259. protected function dealProvider($recv_str)
  260. {
  261. $req_data = json_decode(trim($recv_str), true);
  262. $module = $req_data['module'];
  263. $interface = $req_data['interface'];
  264. $cmd = $req_data['cmd'];
  265. $start_time = isset($req_data['start_time']) ? $req_data['start_time'] : '';
  266. $end_time = isset($req_data['end_time']) ? $req_data['end_time'] : '';
  267. $date = isset($req_data['date']) ? $req_data['date'] : '';
  268. $code = isset($req_data['code']) ? $req_data['code'] : '';
  269. $msg = isset($req_data['msg']) ? $req_data['msg'] : '';
  270. $offset = isset($req_data['offset']) ? $req_data['offset'] : '';
  271. $count = isset($req_data['count']) ? $req_data['count'] : 10;
  272. switch($cmd)
  273. {
  274. case 'get_statistic':
  275. $buffer = json_encode(array('modules'=>$this->getModules($module), 'statistic' => $this->getStatistic($date, $module, $interface)))."\n";
  276. $this->tcpSendToClient($buffer);
  277. break;
  278. case 'get_log':
  279. $buffer = json_encode($this->getStasticLog($module, $interface , $start_time , $end_time, $code = '', $msg = '', $offset='', $count=10))."\n";
  280. $this->tcpSendToClient($buffer);
  281. break;
  282. default :
  283. $this->tcpSendToClient('pack err');
  284. }
  285. $fd = $this->currentDealFd;
  286. $this->event->del($this->connections[$fd], Man\Core\Events\BaseEvent::EV_READ);
  287. $this->event->del($this->connections[$fd], Man\Core\Events\BaseEvent::EV_WRITE);
  288. fclose($this->connections[$fd]);
  289. unset($this->connections[$fd], $this->recvBuffers[$fd], $this->sendBuffers[$fd]);
  290. }
  291. /**
  292. * 获取模块
  293. * @return array
  294. */
  295. public function getModules($current_module = '')
  296. {
  297. $st_dir = WORKERMAN_ROOT_DIR . $this->statisticDir;
  298. $modules_name_array = array();
  299. foreach(glob($st_dir."/*", GLOB_ONLYDIR) as $module_file)
  300. {
  301. $tmp = explode("/", $module_file);
  302. $module = end($tmp);
  303. $modules_name_array[$module] = array();
  304. if($current_module == $module)
  305. {
  306. $st_dir = $st_dir.$current_module.'/';
  307. $all_interface = array();
  308. foreach(glob($st_dir."*") as $file)
  309. {
  310. if(is_dir($file))
  311. {
  312. continue;
  313. }
  314. list($interface, $date) = explode("|", basename($file));
  315. $all_interface[$interface] = $interface;
  316. }
  317. $modules_name_array[$module] = $all_interface;
  318. }
  319. }
  320. return $modules_name_array;
  321. }
  322. /**
  323. * 获得统计数据
  324. * @param string $module
  325. * @param string $interface
  326. * @param int $date
  327. * @return bool/string
  328. */
  329. protected function getStatistic($date, $module, $interface)
  330. {
  331. if(empty($module) || empty($interface))
  332. {
  333. return '';
  334. }
  335. // log文件
  336. $log_file = WORKERMAN_LOG_DIR . $this->statisticDir."{$module}/{$interface}|{$date}";
  337. return @file_get_contents($log_file);
  338. }
  339. /**
  340. * 批量请求
  341. * @param array $request_buffer_array ['ip:port'=>req_buf, 'ip:port'=>req_buf, ...]
  342. * @return array
  343. */
  344. public function multiRequest($request_buffer_array)
  345. {
  346. $client_array = $sock_to_ip = $ip_list = array();
  347. foreach($request_buffer_array as $address => $buffer)
  348. {
  349. $client = stream_socket_client($address, $errno, $errmsg, 1);
  350. if(!$client)
  351. {
  352. $this->notice("connect $address fail");
  353. continue;
  354. }
  355. $client_array[$address] = $client;
  356. stream_set_timeout($client_array[$address], 0, 100000);
  357. fwrite($client_array[$address], $buffer);
  358. stream_set_blocking($client_array[$address], 0);
  359. $sock_to_address[(int)$client] = $address;
  360. }
  361. $read = $client_array;
  362. $write = $except = $read_buffer = array();
  363. $time_start = microtime(true);
  364. // 超时设置
  365. $timeout = 1;
  366. // 轮询处理数据
  367. while(count($read) > 0)
  368. {
  369. if(stream_select($read, $write, $except, $timeout))
  370. {
  371. foreach($read as $socket)
  372. {
  373. $address = $sock_to_address[(int)$socket];
  374. $buf = fread($socket, 8192);
  375. if(!$buf)
  376. {
  377. if(feof($socket))
  378. {
  379. unset($client_array[$address]);
  380. }
  381. continue;
  382. }
  383. if(!isset($read_buffer[$address]))
  384. {
  385. $read_buffer[$address] = $buf;
  386. }
  387. else
  388. {
  389. $read_buffer[$address] .= $buf;
  390. }
  391. // 数据接收完毕
  392. if("\n" === $read_buffer[$address][strlen($read_buffer[$address])-1])
  393. {
  394. unset($client_array[$address]);
  395. }
  396. }
  397. }
  398. // 超时了
  399. if(microtime(true) - $time_start > $timeout)
  400. {
  401. break;
  402. }
  403. $read = $client_array;
  404. }
  405. ksort($read_buffer);
  406. return $read_buffer;
  407. }
  408. /**
  409. * 获取指定日志
  410. *
  411. */
  412. protected function getStasticLog($module, $interface , $start_time = '', $end_time = '', $code = '', $msg = '', $offset='', $count=100)
  413. {
  414. // log文件
  415. $log_file = WORKERMAN_ROOT_DIR . $this->logDir. (empty($start_time) ? date('Y-m-d') : date('Y-m-d', $start_time));
  416. if(!is_readable($log_file))
  417. {
  418. return array('offset'=>0, 'data'=>$log_file . 'not exists or not readable');
  419. }
  420. // 读文件
  421. $h = fopen($log_file, 'r');
  422. // 如果有时间,则进行二分查找,加速查询
  423. if($start_time && $offset === '' && ($file_size = filesize($log_file) > 50000))
  424. {
  425. $offset = $this->binarySearch(0, $file_size, $start_time-1, $h);
  426. $offset = $offset < 1000 ? 0 : $offset - 1000;
  427. }
  428. // 正则表达式
  429. $pattern = "/^([\d: \-]+)\t";
  430. if($module && $module != 'WorkerMan')
  431. {
  432. $pattern .= $module."::";
  433. }
  434. else
  435. {
  436. $pattern .= ".*::";
  437. }
  438. if($interface && $module != 'WorkerMan')
  439. {
  440. $pattern .= $interface."\t";
  441. }
  442. else
  443. {
  444. $pattern .= ".*\t";
  445. }
  446. if($code !== '')
  447. {
  448. $pattern .= "code:$code\t";
  449. }
  450. else
  451. {
  452. $pattern .= "code:\d+\t";
  453. }
  454. if($msg)
  455. {
  456. $pattern .= "msg:$msg";
  457. }
  458. $pattern .= '/';
  459. // 指定偏移位置
  460. if($offset >= 0)
  461. {
  462. fseek($h, (int)$offset);
  463. }
  464. // 查找符合条件的数据
  465. $now_count = 0;
  466. $log_buffer = '';
  467. while(1)
  468. {
  469. if(feof($h))
  470. {
  471. break;
  472. }
  473. // 读1行
  474. $line = fgets($h);
  475. if(preg_match($pattern, $line, $match))
  476. {
  477. // 判断时间是否符合要求
  478. $time = strtotime($match[1]);
  479. if($start_time)
  480. {
  481. if($time<$start_time)
  482. {
  483. continue;
  484. }
  485. }
  486. if($end_time)
  487. {
  488. if($time>$end_time)
  489. {
  490. break;
  491. }
  492. }
  493. // 收集符合条件的log
  494. $log_buffer .= $line;
  495. if(++$now_count >= $count)
  496. {
  497. break;
  498. }
  499. }
  500. }
  501. // 记录偏移位置
  502. $offset = ftell($h);
  503. return array('offset'=>$offset, 'data'=>$log_buffer);
  504. }
  505. /**
  506. * 日志二分查找法
  507. * @param int $start_point
  508. * @param int $end_point
  509. * @param int $time
  510. * @param fd $fd
  511. * @return int
  512. */
  513. protected function binarySearch($start_point, $end_point, $time, $fd)
  514. {
  515. // 计算中点
  516. $mid_point = (int)(($end_point+$start_point)/2);
  517. // 定位文件指针在中点
  518. fseek($fd, $mid_point);
  519. // 读第一行
  520. $line = fgets($fd);
  521. if(feof($fd) || false === $line)
  522. {
  523. return ftell($fd);
  524. }
  525. // 第一行可能数据不全,再读一行
  526. $line = fgets($fd);
  527. if(feof($fd) || false === $line || trim($line) == '')
  528. {
  529. return ftell($fd);
  530. }
  531. // 判断是否越界
  532. $current_point = ftell($fd);
  533. if($current_point>=$end_point)
  534. {
  535. return $end_point;
  536. }
  537. // 获得时间
  538. $tmp = explode("\t", $line);
  539. $tmp_time = strtotime($tmp[0]);
  540. // 判断时间,返回指针位置
  541. if($tmp_time > $time)
  542. {
  543. return $this->binarySearch($start_point, $current_point, $time, $fd);
  544. }
  545. elseif($tmp_time < $time)
  546. {
  547. return $this->binarySearch($current_point, $end_point, $time, $fd);
  548. }
  549. else
  550. {
  551. return $current_point;
  552. }
  553. }
  554. public function tcpSendToClient($str_to_send)
  555. {
  556. $send_len = @stream_socket_sendto($this->connections[$this->currentDealFd], $str_to_send);
  557. if($send_len === strlen($str_to_send))
  558. {
  559. return true;
  560. }
  561. if($send_len > 0)
  562. {
  563. $this->sendBuffers[$this->currentDealFd] = substr($str_to_send, $send_len);
  564. }
  565. else
  566. {
  567. $this->sendBuffers[$this->currentDealFd] = $str_to_send;
  568. }
  569. $this->event->add($this->connections[$this->currentDealFd], \Man\Core\Events\BaseEvent::EV_WRITE, array($this, 'tcpWriteToClient'), array($this->currentDealFd));
  570. }
  571. }
  572. /**
  573. *
  574. * struct statisticPortocol
  575. * {
  576. * unsigned char module_name_len;
  577. * unsigned char interface_name_len;
  578. * float cost_time;
  579. * unsigned char success;
  580. * int code;
  581. * unsigned short msg_len;
  582. * unsigned int time;
  583. * char[module_name_len] module_name;
  584. * char[interface_name_len] interface_name;
  585. * char[msg_len] msg;
  586. * }
  587. *
  588. * @author workerman.net
  589. */
  590. class StatisticProtocol
  591. {
  592. /**
  593. * 包头长度
  594. * @var integer
  595. */
  596. const PACKEGE_FIXED_LENGTH = 17;
  597. /**
  598. * udp 包最大长度
  599. * @var integer
  600. */
  601. const MAX_UDP_PACKGE_SIZE = 65507;
  602. /**
  603. * char类型能保存的最大数值
  604. * @var integer
  605. */
  606. const MAX_CHAR_VALUE = 255;
  607. /**
  608. * usigned short 能保存的最大数值
  609. * @var integer
  610. */
  611. const MAX_UNSIGNED_SHORT_VALUE = 65535;
  612. /**
  613. * 编码
  614. * @param string $module
  615. * @param string $interface
  616. * @param float $cost_time
  617. * @param int $success
  618. * @param int $code
  619. * @param string $msg
  620. * @return string
  621. */
  622. public static function encode($module, $interface , $cost_time, $success, $code = 0,$msg = '')
  623. {
  624. // 防止模块名过长
  625. if(strlen($module) > self::MAX_CHAR_VALUE)
  626. {
  627. $module = substr($module, 0, self::MAX_CHAR_VALUE);
  628. }
  629. // 防止接口名过长
  630. if(strlen($interface) > self::MAX_CHAR_VALUE)
  631. {
  632. $interface = substr($interface, 0, self::MAX_CHAR_VALUE);
  633. }
  634. // 防止msg过长
  635. $module_name_length = strlen($module);
  636. $interface_name_length = strlen($interface);
  637. $avalible_size = self::MAX_UDP_PACKGE_SIZE - self::PACKEGE_FIXED_LENGTH - $module_name_length - $interface_name_length;
  638. if(strlen($msg) > $avalible_size)
  639. {
  640. $msg = substr($msg, 0, $avalible_size);
  641. }
  642. // 打包
  643. return pack('CCfCNnN', $module_name_length, $interface_name_length, $cost_time, $success ? 1 : 0, $code, strlen($msg), time()).$module.$interface.$msg;
  644. }
  645. /**
  646. * 解包
  647. * @param string $bin_data
  648. * @return array
  649. */
  650. public static function decode($bin_data)
  651. {
  652. // 解包
  653. $data = unpack("Cmodule_name_len/Cinterface_name_len/fcost_time/Csuccess/Ncode/nmsg_len/Ntime", $bin_data);
  654. $module = substr($bin_data, self::PACKEGE_FIXED_LENGTH, $data['module_name_len']);
  655. $interface = substr($bin_data, self::PACKEGE_FIXED_LENGTH + $data['module_name_len'], $data['interface_name_len']);
  656. $msg = substr($bin_data, self::PACKEGE_FIXED_LENGTH + $data['module_name_len'] + $data['interface_name_len']);
  657. return array(
  658. 'module' => $module,
  659. 'interface' => $interface,
  660. 'cost_time' => $data['cost_time'],
  661. 'success' => $data['success'],
  662. 'time' => $data['time'],
  663. 'code' => $data['code'],
  664. 'msg' => $msg,
  665. );
  666. }
  667. }