1.4升级指南
升级前请做好备份,执行以下命令升级
composer require workerman/webman-framework ^1.4.3 && composer require webman/console ^1.0.27 && php webman install
注意 如果无法升级,很可能是因为使用了composer代理,请使用以下命令
composer config -g --unset repos.packagist恢复使用composer官方数据源
功能特性及变更
应用插件
1.4版本支持应用插件,更多请参考应用插件
自动路由
1.4版本支持各种复杂的控制器目录规则,例如
appapp├── admin│ └── v1│ └── v2│ └── v3│ └── controller│ └── Index.php└── controller├── v1│ └── Index.php└── v2└── v3└── Index.php
也就是说 webman/auto-route 插件不再需要了
控制器复用开关
1.4版本允许关闭控制器复用,在config/app.php中设置'controller_reuse' => false,,这样每个请求都会重新初始化一个新的控制器,也就是说每个请求都会触发对应控制器的__construct()构造函数,开发者可以在构造函数中为每个请求执行一些请求处理前的初始化工作。
因为可以关闭控制器复用,所以webman/action-hook 插件的不再需要了。
开启http服务
1.4 版本支持开启多个端口提供http服务。 因为webman请求是排队处理的,如果某个请求处理速度慢,会影响排队中的其它请求。 这时候我们可以再开一些进程,把速度慢的接口放在这些进程去处理。
例如新开一组8686端口的http进程只需要在 config/process.php 里增加如下配置。
return [// ... 这里省略了其它配置 ...'task' => ['handler' => \Webman\App::class,'listen' => 'http://0.0.0.0:8686','count' => 8, // 进程数'constructor' => ['request_class' => \support\Request::class, // request类设置'logger' => \support\Log::channel('default'), // 日志实例'app_path' => app_path(), // app目录位置'public_path' => public_path() // public目录位置]]];
这样慢接口可以走 http://127.0.0.1:8686/ 这组进程,不影响其它进程的业务处理。
为了让前端无感知端口的区别,可以在nginx加一个到8686端口的代理。假设慢接口请求路径都是以/pay开头,整个nginx配置类似如下:
upstream webman {server 127.0.0.1:8787;keepalive 10240;}# 新增一个8686 upstreamupstream slow {server 127.0.0.1:8686;keepalive 10240;}server {server_name webman.com;listen 80;access_log off;root /path/webman/public;# 以/pay开头的请求走8686端口,请按实际情况将/pay更改为你需要的前缀location /pay {proxy_set_header X-Real-IP $remote_addr;proxy_set_header Host $host;proxy_http_version 1.1;proxy_set_header Connection "";proxy_pass http://slow;}# 其它请求走原8787端口location / {proxy_set_header X-Real-IP $remote_addr;proxy_set_header Host $host;proxy_http_version 1.1;proxy_set_header Connection "";if (!-f $request_filename){proxy_pass http://webman;}}}
这样客户端访问域名.com/pay/xxx时将会走单独的8686端口处理,不影响8787端口的请求处理。
视图文件配置
后缀只能在view.php 的 options选项中配置。 不再支持的用法
use support\view\Raw;return ['handler' => Raw::class,'view_suffix' => '.php'];
正确的用法
use support\view\Raw;return ['handler' => Raw::class,'options' => ['view_suffix' => '.php']];
session驱动命名空间变动
webman从1.4.0起更改了SessionHandler类的命名空间,由原来的
use Webman\FileSessionHandler;use Webman\RedisSessionHandler;use Webman\RedisClusterSessionHandler;
改为
use Webman\Session\FileSessionHandler;use Webman\Session\RedisSessionHandler;use Webman\Session\RedisClusterSessionHandler;
为了避免升级后程序直接报错,Webman\FileSessionHandler类仍然被保留一段时间,在未来版本中会被彻底移除。
此变更影响config/session.php的'handler'配置。
