Ejemplo n.º 1
0
 private function doRequest($sendData, $ip = "", $port = "")
 {
     //get client obj
     try {
         $client = $this->getClientObj($ip, $port);
     } catch (\Exception $e) {
         return \DoraDRPC\Base\Packet::packFormat($e->getMessage(), $e->getCode());
     }
     $ret = $client->send($sendData);
     //ok fail
     if (!$ret) {
         $errorcode = $client->errCode;
         //destroy error client obj to make reconncet
         unset(self::$client[$this->currentClientKey]);
         if ($errorcode == 0) {
             $msg = "connect fail.check host dns.";
             $errorcode = -1;
             $Packet = \DoraDRPC\Base\Packet::packFormat($msg, $errorcode);
         } else {
             $msg = socket_strerror($errorcode);
             $Packet = \DoraDRPC\Base\Packet::packFormat($msg, $errorcode);
         }
         return $Packet;
     }
     //recive the response
     $result = $client->recv();
     //recive error check
     if ($result !== false) {
         return \DoraDRPC\Base\Packet::packDecode($result);
     } else {
         return \DoraDRPC\Base\Packet::packFormat("the recive wrong or timeout", 100009);
     }
 }
Ejemplo n.º 2
0
 public final function onTask($serv, $task_id, $from_id, $data)
 {
     swoole_set_process_name("DoraDRPC_TASK|{$task_id}|{$data["api"]["name"]}");
     try {
         $data["result"] = $this->callbackDoWork($data);
         //fixed the result more than 8k timeout bug
         $data = serialize($data);
         if (strlen($data) > 8000) {
             $temp_file = tempnam(sys_get_temp_dir(), 'swmore8k');
             file_put_contents($temp_file, $data);
             return '$$$$$$$$' . $temp_file;
         } else {
             return $data;
         }
     } catch (\Exception $e) {
         $data["result"] = \DoraDRPC\Base\Packet::packFormat($e->getMessage(), $e->getCode());
         return $data;
     }
 }
Ejemplo n.º 3
0
 public function callbackProcessResult($serv, $task_id, $data)
 {
     $fd = $data["fd"];
     if (!isset($this->_taskinfo[$fd]) || !$data["result"]) {
         unset($this->_taskinfo[$fd]);
         return true;
     }
     $key = $this->_taskinfo[$fd]["task"][$task_id];
     $this->_taskinfo[$fd]["result"][$key] = $data["result"];
     unset($this->_taskinfo[$fd]["task"][$task_id]);
     switch ($data["type"]) {
         case \DoraDRPC\Base\DoraConst::SW_SYNC_SINGLE:
             $Packet = \DoraDRPC\Base\Packet::packFormat("OK", 0, $data["result"]);
             $Packet["guid"] = $this->_taskinfo[$fd]["guid"];
             $Packet = \DoraDRPC\Base\Packet::packEncode($Packet);
             $serv->send($fd, $Packet);
             unset($this->_taskinfo[$fd]);
             return true;
             break;
         case \DoraDRPC\Base\DoraConst::SW_SYNC_MULTI:
             if (count($this->_taskinfo[$fd]["task"]) == 0) {
                 $Packet = \DoraDRPC\Base\Packet::packFormat("OK", 0, $this->_taskinfo[$fd]["result"]);
                 $Packet["guid"] = $this->_taskinfo[$fd]["guid"];
                 $Packet = \DoraDRPC\Base\Packet::packEncode($Packet);
                 $serv->send($fd, $Packet);
                 unset($this->_taskinfo[$fd]);
                 return true;
             } else {
                 return true;
             }
             break;
         default:
             unset($this->_taskinfo[$fd]);
             return true;
             break;
     }
 }
Ejemplo n.º 4
0
 public function onPacket(\swoole_server $server, $data, $client_info)
 {
     $data = \DoraDRPC\Base\Packet::packDecode($data);
     //$server->sendto($client_info['address'], $client_info['port'], \DoraDRPC\Base\Packet::packEncode(array()));
     //var_dump($server, $data);
 }