Example #1
0
 public function onRequest($request, $response)
 {
     $filename = ZPHP::getRootPath() . DS . 'webroot' . $request->server['path_info'];
     if (is_file($filename)) {
         //解析静态文件
         $response->header("Content-Type", $this->getMime($filename) . '; charset=utf-8');
         $response->end(file_get_contents($filename));
         return;
     }
     $param = [];
     if (!empty($request->get)) {
         $param = $request->get;
     }
     if (!empty($request->post)) {
         $param += $request->post;
     }
     $_SERVER['HTTP_USER_AGENT'] = $request->header['user-agent'];
     Request::parse($param);
     Request::setViewMode('Php');
     Request::setHttpServer(1);
     Response::setResponse($response);
     try {
         $result = ZRoute::route();
     } catch (\Exception $e) {
         $model = Formater::exception($e);
         $model['_view_mode'] = 'Json';
         $result = Response::display($model);
     }
     $response->end($result);
     Request::setViewMode(ZConfig::getField('project', 'view_mode', 'Json'));
     Request::setHttpServer(0);
 }
Example #2
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();
 }
Example #3
0
 public function onWorkerStart($server, $workerId)
 {
     parent::onWorkerStart($server, $workerId);
     Protocol\Request::setHttpServer(1);
 }