🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
### 安装 支持composer安装 ```php composer require xaviertony/xavier-swoole ``` 注意:\think\Request 增加如下静态方法。 由于TP运行在Apache或者NGINX下,是每次请求后都会销毁,所以这里的单例并不会造成什么问题,但是在Swoole下,由于常驻内存,所以请求单例一旦实例化则不会改变,所以这里就将其删除,每次请求后重新实例化 ```php public static function deletethis() { if (!is_null(self::$instance)) { self::$instance=null; } } ``` 修改如下代码,由于采用命令行模式运行无论什么请求都会被认为是get ```php /** * 当前的请求类型 * @access public * @param bool $method true 获取原始请求类型 * @return string */ public function method($method = false) { if (true === $method) { // 获取原始请求类型 $this->method = IS_CLI ?(defined('IS_SWOOLE')?((isset($this->server['REQUEST_METHOD'])? $this->server['REQUEST_METHOD'] : isset($_SERVER['REQUEST_METHOD'])?$_SERVER['REQUEST_METHOD']:'GET')):'GET') : (isset($this->server['REQUEST_METHOD']) ? $this->server['REQUEST_METHOD'] : $_SERVER['REQUEST_METHOD']); } elseif (!$this->method) { if (isset($_POST[Config::get('var_method')])) { $this->method = strtoupper($_POST[Config::get('var_method')]); $this->{$this->method}($_POST); } elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) { $this->method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']); } else { $this->method = IS_CLI ?(defined('IS_SWOOLE')?((isset($this->server['REQUEST_METHOD'])? $this->server['REQUEST_METHOD'] : isset($_SERVER['REQUEST_METHOD'])?$_SERVER['REQUEST_METHOD']:'GET')):'GET') : (isset($this->server['REQUEST_METHOD']) ? $this->server['REQUEST_METHOD'] : $_SERVER['REQUEST_METHOD']); } } return $this->method; } ``` 启动命令 ```sh php think swoole start ``` 守护启动 ```sh php think swoole start -d ``` 停止服务 ```sh php think swoole stop ```