升級(jí)前請做好備份,執(zhí)行以下命令升級(jí)
composer require workerman/webman-framework ^1.4.3 && composer require webman/console ^1.0.27 && php webman install
注意
如果無法升級(jí),很可能是因?yàn)槭褂昧薱omposer代理,請使用以下命令composer config -g --unset repos.packagist
恢復(fù)使用composer官方數(shù)據(jù)源
1.4版本支持應(yīng)用插件,更多請參考應(yīng)用插件
1.4版本支持各種復(fù)雜的控制器目錄規(guī)則,例如
app
app
├── admin
│?? └── v1
│?? └── v2
│?? └── v3
│?? └── controller
│?? └── Index.php
└── controller
├── v1
│?? └── Index.php
└── v2
└── v3
└── Index.php
也就是說 webman/auto-route
插件不再需要了
1.4版本允許關(guān)閉控制器復(fù)用,在config/app.php
中設(shè)置'controller_reuse' => false,
,這樣每個(gè)請求都會(huì)重新初始化一個(gè)新的控制器,也就是說每個(gè)請求都會(huì)觸發(fā)對(duì)應(yīng)控制器的__construct()
構(gòu)造函數(shù),開發(fā)者可以在構(gòu)造函數(shù)中為每個(gè)請求執(zhí)行一些請求處理前的初始化工作。
因?yàn)榭梢躁P(guān)閉控制器復(fù)用,所以webman/action-hook
插件的不再需要了。
1.4 版本支持開啟多個(gè)端口提供http服務(wù)。
因?yàn)閣ebman請求是排隊(duì)處理的,如果某個(gè)請求處理速度慢,會(huì)影響排隊(duì)中的其它請求。
這時(shí)候我們可以再開一些進(jìn)程,把速度慢的接口放在這些進(jìn)程去處理。
例如新開一組8686端口的http進(jìn)程只需要在 config/process.php
里增加如下配置。
return [
// ... 這里省略了其它配置 ...
'task' => [
'handler' => \Webman\App::class,
'listen' => 'http://0.0.0.0:8686',
'count' => 8, // 進(jìn)程數(shù)
'constructor' => [
'request_class' => \support\Request::class, // request類設(shè)置
'logger' => \support\Log::channel('default'), // 日志實(shí)例
'app_path' => app_path(), // app目錄位置
'public_path' => public_path() // public目錄位置
]
]
];
這樣慢接口可以走 http://127.0.0.1:8686/
這組進(jìn)程,不影響其它進(jìn)程的業(yè)務(wù)處理。
為了讓前端無感知端口的區(qū)別,可以在nginx加一個(gè)到8686端口的代理。假設(shè)慢接口請求路徑都是以/pay
開頭,整個(gè)nginx配置類似如下:
upstream webman {
server 127.0.0.1:8787;
keepalive 10240;
}
# 新增一個(gè)8686 upstream
upstream 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端口
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
時(shí)將會(huì)走單獨(dú)的8686端口處理,不影響8787端口的請求處理。
后綴只能在view.php 的 options選項(xiàng)中配置。
不再支持的用法
use support\view\Raw;
return [
'handler' => Raw::class,
'view_suffix' => 'php'
];
正確的用法
use support\view\Raw;
return [
'handler' => Raw::class,
'options' => [
'view_suffix' => '.php'
]
];
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;
為了避免升級(jí)后程序直接報(bào)錯(cuò),Webman\FileSessionHandler
類仍然被保留一段時(shí)間,在未來版本中會(huì)被徹底移除。
此變更影響config/session.php
的'handler'
配置。
1、正想問“如何優(yōu)雅的修改組件”問題來著,應(yīng)用插件就橫空出世了,哈哈~不過順便問下大神,假如我想修改一款組件,首先不能直接在vendor中直接修改(下次升級(jí)會(huì)覆蓋掉),那放在應(yīng)用插件里是不是最好的方法呢?
2、自動(dòng)路由 終于讓我盼到了~
3、控制器復(fù)用開關(guān):如果能單獨(dú)控制某個(gè)控制器復(fù)用就更好了,但不建議用 action-hook 插件,首先是它初始化的地方有點(diǎn)奇怪(在全局中間件在后,路由中間件之前。。),其次如果和 'controller_reuse' => false 一起使用的話會(huì)有點(diǎn)小bug:會(huì)創(chuàng)建兩個(gè)控制器,一個(gè)還不會(huì)析構(gòu)(估計(jì)是 action-hook插件內(nèi)部使用了 Container::get 創(chuàng)建了控制器)。
./composer.json has been updated
Running composer update workerman/webman-framework
Loading composer repositories with package information
Info from https://repo.packagist.org: #StandWithUkraine
Updating dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Generating autoload files
11 packages you are using are looking for funding.
Use the composer fund
command to find out more!
No security vulnerability advisories found
Warning from https://repo.packagist.org: Support for Composer 1 is deprecated and some packages will not be available. You should upgrade to Composer 2. See https://blog.packagist.com/deprecating-composer-1-support/
Info from https://repo.packagist.org: #StandWithUkraine
升級(jí)好像卡住了
composer require workerman/webman-framework
composer require webman/console
php webman install
我拆開后運(yùn)行 可以了