Esempio n. 1
0
 /**
  * 处理受到的数据
  * @param TcpConnection $connection
  * @return void
  */
 public function onConnect($connection)
 {
     $socket = $connection->getSocket();
     $t_socket = new Thrift\Transport\TSocket();
     $t_socket->setHandle($socket);
     $transport_name = '\\Thrift\\Transport\\' . $this->thriftTransport;
     $transport = new $transport_name($t_socket);
     $protocol_name = '\\Thrift\\Protocol\\' . $this->thriftProtocol;
     $protocol = new $protocol_name($transport);
     // 执行处理
     try {
         // 先初始化一个
         $protocol->fname == 'none';
         // 统计开始时间
         \Thrift\Statistics\StatisticClient::tick();
         // 业务处理
         $this->processor->process($protocol, $protocol);
         \Thrift\Statistics\StatisticClient::report($this->name, $protocol->fname, 1, 0, '', $this->statisticAddress);
     } catch (\Exception $e) {
         \Thrift\Statistics\StatisticClient::report($this->name, $protocol->fname, 0, $e->getCode(), $e, $this->statisticAddress);
         ThriftWorker::log('CODE:' . $e->getCode() . ' MESSAGE:' . $e->getMessage() . "\n" . $e->getTraceAsString() . "\nCLIENT_IP:" . $connection->getRemoteIp() . "\n");
         $connection->send($e->getMessage());
     }
 }
Esempio n. 2
0
 /**
  * 处理受到的数据
  * @param event_buffer $event_buffer
  * @param int $fd
  * @return void
  */
 public function dealInputBase($connection, $flag, $fd = null)
 {
     $this->currentDealFd = (int) $connection;
     if (feof($connection)) {
         $this->statusInfo['client_close']++;
         return $this->closeClient($this->currentDealFd);
     }
     $socket = new Thrift\Transport\TSocket();
     $socket->setHandle($connection);
     $transport = new $this->thriftTransport($socket);
     $protocol = new $this->thriftProtocol($transport);
     // 执行处理
     try {
         // 先初始化一个
         $protocol->fname == 'none';
         // 统计开始时间
         \Thrift\Statistics\StatisticClient::tick();
         // 业务处理
         $this->processor->process($protocol, $protocol);
         \Thrift\Statistics\StatisticClient::report($this->workerName, $protocol->fname, 1, 0, '', $this->statisticAddress);
     } catch (\Exception $e) {
         \Thrift\Statistics\StatisticClient::report($this->workerName, $protocol->fname, 0, $e->getCode(), $e, $this->statisticAddress);
         $this->notice('CODE:' . $e->getCode() . ' MESSAGE:' . $e->getMessage() . "\n" . $e->getTraceAsString() . "\nCLIENT_IP:" . $this->getRemoteIp() . "\nBUFFER:[" . var_export($this->recvBuffers[$fd]['buf'], true) . "]\n");
         $this->statusInfo['throw_exception']++;
         $this->sendToClient($e->getMessage());
     }
     // 是否是长连接
     if (!$this->isPersistentConnection) {
         $this->closeClient($fd);
     }
     // 检查是否是关闭状态或者是否到达请求上限
     if ($this->workerStatus == self::STATUS_SHUTDOWN || $this->statusInfo['total_request'] >= $this->maxRequests) {
         // 停止服务
         $this->stop();
         // EXIT_WAIT_TIME秒后退出进程
         pcntl_alarm(self::EXIT_WAIT_TIME);
     }
 }