Beispiel #1
0
 public function run($data, $fd = null)
 {
     $server = Protocol\Factory::getInstance(Core\Config::getField('socket', 'protocol', 'Http'));
     $server->setFd($fd);
     $server->parse($data);
     return Core\Route::route($server);
 }
Beispiel #2
0
 public function run()
 {
     $server = Protocol\Factory::getInstance('Cli');
     Protocol\Request::setServer($server);
     Protocol\Request::parse($_SERVER['argv']);
     return Core\Route::route();
 }
Beispiel #3
0
 public function api($params)
 {
     if (!$this->protocol) {
         $this->protocol = Protocol\Factory::getInstance('Rpc');
     }
     $this->protocol->parse($params);
     return Core\Route::route($this->protocol);
 }
Beispiel #4
0
 public function run()
 {
     if (!$this->protocol) {
         $this->protocol = Protocol\Factory::getInstance('Http');
     }
     $this->protocol->parse($_REQUEST);
     return Core\Route::route($this->protocol);
 }
Beispiel #5
0
 public function run()
 {
     if (!$this->protocol) {
         $this->protocol = Protocol\Factory::getInstance('Cli');
     }
     $this->protocol->parse($_SERVER['argv']);
     return Core\Route::route($this->protocol);
 }
Beispiel #6
0
 public function run($data)
 {
     $server = Protocol\Factory::getInstance('Http');
     $server->parse($data);
     \ob_start();
     Core\Route::route($server);
     $result = \ob_get_contents();
     \ob_end_clean();
     return $result;
 }
Beispiel #7
0
 public function run($data, $fd)
 {
     $server = Protocol\Factory::getInstance('ZRpack');
     $server->setFd($fd);
     $result = array();
     if (false === $server->parse($data)) {
         return $result;
     }
     $result[] = Core\Route::route($server);
     while ($server->parse("")) {
         $result[] = Core\Route::route($server);
     }
     return $result;
 }
Beispiel #8
0
 public function run()
 {
     $config = Config::get('socket');
     if (empty($config)) {
         throw new \Exception("socket config empty");
     }
     $socket = SFactory::getInstance($config['adapter'], $config);
     if (method_exists($socket, 'setClient')) {
         $client = CFactory::getInstance($config['client_class']);
         $socket->setClient($client);
     }
     Request::setServer(ZProtocol::getInstance(Config::getField('socket', 'protocol')));
     Request::setLongServer();
     Request::setHttpServer(0);
     $socket->run();
 }
Beispiel #9
0
 public function onReceive()
 {
     $params = func_get_args();
     $data = trim($params[3]);
     $serv = $params[0];
     $fd = $params[1];
     echo "get data {$data} from {$fd}\n";
     if (empty($data)) {
         return;
     }
     $server = Protocol\Factory::getInstance(Core\Config::getField('socket', 'protocol'));
     $result = $server->parse($data);
     if (empty($result['a'])) {
         \swoole_server_send($serv, $fd, "server:" . $data);
     } else {
         $server->setFd($fd);
         $server = $this->route($server);
         \swoole_server_send($serv, $fd, $server->getData());
     }
 }
Beispiel #10
0
 public function onReceive()
 {
     $params = func_get_args();
     $client_id = $params[0];
     $data = trim($params[1]);
     echo "get data {$data} from {$client_id}\n";
     if (empty($data)) {
         return;
     }
     $server = Protocol\Factory::getInstance(Core\Config::getField('socket', 'protocol'));
     $result = $server->parse($data);
     if (!empty($result['a'])) {
         $server->setFd($client_id);
         $server = $this->route($server);
         $data = $server->getData();
     } else {
         $data = 'Server:' . $data;
     }
     return $this->server->send($client_id, $data);
 }
Beispiel #11
0
 public function onReceive()
 {
     $beginTime = microtime(true);
     $params = func_get_args();
     $data = trim($params[3]);
     $serv = $params[0];
     $fd = $params[1];
     Debug::debug("get data: {$data} from {$fd}\n");
     if (empty($data)) {
         return;
     }
     //todo remove. for flash
     if ('<policy' == substr($data, 0, 7)) {
         \swoole_server_send($params[0], $params[1], "<cross-domain-policy>\n                    <allow-access-from domain='*' to-ports='*' />\n                    </cross-domain-policy>");
         return;
     }
     //:~end
     //check dataeof
     $data = $this->parsedataEof($data);
     $server = Protocol\Factory::getInstance(Core\Config::getField('socket', 'protocol'));
     $result = $server->parse($data);
     if (empty($result['a'])) {
         $result = array('e_no' => 9999999, 'e_msg' => 'wrong client data', 'data' => $data);
         $d = \json_encode($result);
         $d = $this->getDataEof($d);
         \swoole_server_send($serv, $fd, $d);
     } else {
         $server->setFd($fd);
         $server = $this->route($server);
         $returnData = $server->getData();
         $endTime = (microtime(true) - $beginTime) * 1000;
         $returnData['_elapsed'] = $endTime;
         $d = \json_encode($returnData);
         $d = $this->getDataEof($d);
         \swoole_server_send($serv, $fd, $d);
         Debug::info("server return data:{$d}\n");
         Debug::info("[server time used:{$endTime} ms.]\n");
     }
 }
Beispiel #12
0
 public function run()
 {
     $server = Protocol\Factory::getInstance('Cli');
     $server->parse($_SERVER['argv']);
     Core\Route::route($server);
 }
Beispiel #13
0
 private function _route($data)
 {
     try {
         $server = Protocol\Factory::getInstance(ZConfig::getField('socket', 'protocol', 'Rpc'));
         $server->parse($data);
         $result = Core\Route::route($server);
         return $result;
     } catch (\Exception $e) {
         $result = Formater::exception($e);
         ZPHP\Common\Log::info('zchat', [var_export($result, true)]);
         return null;
     }
 }
Beispiel #14
0
 public function run()
 {
     Protocol\Request::setServer(Protocol\Factory::getInstance('Http'));
     Protocol\Request::parse($_REQUEST);
     return Core\Route::route();
 }
Beispiel #15
0
 public function onStart()
 {
     if (!$this->protocol) {
         $this->protocol = Protocol\Factory::getInstance(ZConfig::getField('project', 'protocol', $this->protocolName));
     }
 }
Beispiel #16
0
 public function run()
 {
     $server = Protocol\Factory::getInstance('Http');
     $server->parse($_REQUEST);
     Core\Route::route($server);
 }
Beispiel #17
0
 public function run()
 {
     $server = Protocol\Factory::getInstance('Protocol\\WebSocket');
     $server->parse($_REQUEST);
     return Core\Route::route($server);
 }
Beispiel #18
0
 public function work()
 {
     $server = Protocol\Factory::getInstance(Core\Config::getField('socket', 'protocol'));
     $queueService = ZQueue::getInstance(ZConfig::getField('queue', 'adapter'));
     while (true) {
         $data = $queueService->get(ZConfig::getField('queue', 'key'));
         if (!empty($data)) {
             $this->_reqnum++;
             $result = $server->parse($data);
             if (!empty($result['fd'])) {
                 $server->setFd($result['fd']);
             }
             if (!empty($result)) {
                 $server = $this->route($server);
                 $server->sendMaster(['pid' => posix_getpid(), 'reqnum' => $this->_reqnum]);
             }
         }
         usleep(500);
     }
 }
Beispiel #19
0
 public function api($params)
 {
     Protocol\Request::setServer(Protocol\Factory::getInstance('Rpc'));
     Protocol\Request::parse($params);
     return Core\Route::route();
 }
Beispiel #20
0
 public function api($params)
 {
     $server = Protocol\Factory::getInstance('Rpc');
     $server->parse($params);
     return Core\Route::route($server);
 }