コード例 #1
0
 function onRequest(Swoole\Request $request)
 {
     $response = new Swoole\Response();
     $php = Swoole::getInstance();
     $request->setGlobal();
     //        if($this->doStaticRequest($request, $response))
     //        {
     //            return $response;
     //        }
     //将对象赋值到控制器
     $php->request = $request;
     $php->response = $response;
     $response->head['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0';
     $response->head['Pragma'] = 'no-cache';
     try {
         ob_start();
         /*---------------------处理MVC----------------------*/
         $response->body = $php->runMVC();
         $response->body .= ob_get_contents();
         ob_end_clean();
     } catch (\Exception $e) {
         if ($request->finish != 1) {
             $this->http_error(404, $response, $e->getMessage());
         }
     }
     if (!isset($response->head['Content-Type'])) {
         $response->head['Content-Type'] = 'text/html; charset=' . $this->config['apps']['charset'];
     }
     //重定向
     if (isset($response->head['Location'])) {
         $response->send_http_status(301);
     }
     return $response;
 }
コード例 #2
0
 /**
  * 将swoole扩展产生的请求对象数据赋值给框架的Request对象
  * @param Swoole\Request $request
  */
 function assign(Swoole\Request $request)
 {
     if (isset($this->request->get)) {
         $request->get = $this->request->get;
     }
     if (isset($this->request->post)) {
         $request->post = $this->request->post;
     }
     if (isset($this->request->files)) {
         $request->files = $this->request->files;
     }
     if (isset($this->request->cookie)) {
         $request->cookie = $this->request->cookie;
     }
     if (isset($this->request->server)) {
         foreach ($this->request->server as $key => $value) {
             $request->server[strtoupper($key)] = $value;
         }
         $request->remote_ip = $this->request->server['remote_addr'];
     }
     $request->header = $this->request->header;
     $request->setGlobal();
 }
コード例 #3
0
ファイル: HttpServer.php プロジェクト: jasonshaw/framework-1
 /**
  * 动态请求
  * @param $request
  * @param $response
  * @return unknown_type
  */
 function processDynamic(Swoole\Request $request, Swoole\Response $response)
 {
     $path = $this->document_root . '/' . $request->meta['path'];
     if (is_file($path)) {
         $request->setGlobal();
         $response->head['Content-Type'] = 'text/html';
         ob_start();
         try {
             include $path;
             $response->body = ob_get_contents();
         } catch (\Exception $e) {
             $response->setHttpStatus(500);
             $response->body = $e->getMessage() . '!<br /><h1>' . self::SOFTWARE . '</h1>';
         }
         ob_end_clean();
     } else {
         $this->httpError(404, $response, "页面不存在({$request->meta['path']})!");
     }
 }
コード例 #4
0
ファイル: Server.php プロジェクト: TimeForgetted/houxue_push
 /**
  * Request come
  * @param Swoole\Request $request
  * @return Swoole\Response
  */
 function onRequest(Swoole\Request $request)
 {
     return $request->isWebSocket() ? $this->onWebSocketRequest($request) : $this->onHttpRequest($request);
 }
コード例 #5
0
 /**
  * Clean and fire onWsConnect().
  * @param Swoole\Request $request
  * @param Swoole\Response $response
  */
 function afterResponse(Swoole\Request $request, Swoole\Response $response)
 {
     if ($request->isWebSocket()) {
         $conn = array('header' => $request->header, 'time' => time());
         $this->connections[$request->fd] = $conn;
         if (count($this->connections) > $this->max_connect) {
             $this->cleanConnection();
         }
         $this->onWsConnect($request->fd, $request);
     }
     parent::afterResponse($request, $response);
 }
コード例 #6
0
 /**
  * 动态请求
  * @param $request
  * @param $response
  * @return unknown_type
  */
 function processDynamic(Swoole\Request $request, Swoole\Response $response)
 {
     $request->setGlobal();
     $response->head['Content-Type'] = 'text/html';
     ob_start();
     try {
         $this->application->bootstrap();
         $request_uri = $request->meta['path'];
         $this->application->getDispatcher()->dispatch(new \Yaf_Request_Http($request_uri));
         $response->body = ob_get_contents();
     } catch (\Exception $e) {
         $response->setHttpStatus(500);
         $response->body = $e->getMessage() . '!<br /><h1>' . self::SOFTWARE . '</h1>';
     }
     ob_end_clean();
 }
コード例 #7
0
 function afterResponse(Swoole\Request $request, Swoole\Response $response)
 {
     if (!$this->keepalive or $response->head['Connection'] == 'close') {
         $this->server->close($request->fd);
     }
     $request->unsetGlobal();
     //清空request缓存区
     unset($this->requests[$request->fd]);
     unset($request);
     unset($response);
 }