webman2.1 使用了swoole作為驅(qū)動
在測試協(xié)程上下文傳輸時報錯
composer
"php": ">=8.1",
"workerman/webman-framework": "^2.1",
"monolog/monolog": "^2.0",
"webman/console": "^2.1",
"webman/rate-limiter": "^1.1",
"workerman/validation": "^3.1",
"webman/redis": "^2.1",
"illuminate/events": "^11.43",
"vlucas/phpdotenv": "^5.6",
"webman/cache": "^2.1",
"workerman/coroutine": "^1.1.3",
"webman/database": "^2.1",
"illuminate/pagination": "*",
"symfony/var-dumper": "^7.2",
"webman/log": "^2.1"
發(fā)下 config/process.php
use support\Log;
use support\Request;
use app\process\Http;
global $argv;
return [
'webman' => [
'handler' => Http::class,
'listen' => 'http://0.0.0.0:8787',
'count' => 2,
'user' => '',
'group' => '',
'reusePort' => false,
'eventLoop' => '',
'context' => [],
'constructor' => [
'requestClass' => Request::class,
'logger' => Log::channel('default'),
'appPath' => app_path(),
'publicPath' => public_path()
]
],
'swoole' =>[
'handler' => Http::class,
'listen' => 'http://0.0.0.0:8888',
'count' => 2,
'user' => '',
'group' => '',
'reusePort' => false,
'eventLoop' => Workerman\Events\Swoole::class,
'context' => [],
'constructor' => [
'requestClass' => Request::class,
'logger' => Log::channel('default'),
'appPath' => app_path(),
'publicPath' => public_path()
]
],
// File update detection and automatic reload
'monitor' => [
'handler' => app\process\Monitor::class,
'reloadable' => false,
'constructor' => [
// Monitor these directories
'monitorDir' => array_merge([
app_path(),
config_path(),
base_path() . '/process',
base_path() . '/support',
base_path() . '/resource',
base_path() . '/.env',
], glob(base_path() . '/plugin//app'), glob(base_path() . '/plugin//config'), glob(base_path() . '/plugin/*/api')),
// Files with these suffixes will be monitored
'monitorExtensions' => [
'php', 'html', 'htm', 'env'
],
'options' => [
'enable_file_monitor' => !in_array('-d', $argv) && DIRECTORY_SEPARATOR === '/',
'enable_memory_monitor' => DIRECTORY_SEPARATOR === '/',
]
]
]
];
從報錯看是使用了錯誤的Request類,正常應(yīng)該使用support/Request
。
調(diào)用棧里看到使用的是 Workerman\Protocols\Http\Request
類是在 config/process.php 里的 requestClass 指定的,可能你改了什么東西,用了錯誤的Request類。
寫一個能穩(wěn)定復(fù)現(xiàn)的例子,打包發(fā)到我郵箱 walkor@workerman.net
寫明重現(xiàn)步驟。主要,要能重現(xiàn)問題的例子。
Error: Call to undefined method Workerman\Protocols\Http\Request::getRealIp() in /www/apiV2/vendor/workerman/webman-framework/src/Exception/ExceptionHandler.php:68 Stack trace: #0 /www/apiV2/vendor/workerman/webman-framework/src/support/exception/Handler.php(35): Webman\Exception\ExceptionHandler->report(Object(TypeError)) #1 /www/apiV2/vendor/workerman/webman-framework/src/App.php(280): support\exception\Handler->report(Object(TypeError)) #2 /www/apiV2/vendor/workerman/webman-framework/src/App.php(354): Webman\App::exceptionResponse(Object(TypeError), Object(Workerman\Protocols\Http\Request)) #3 /www/apiV2/vendor/workerman/webman-framework/src/App.php(150): Webman\App::Webman\{closure}(Object(Workerman\Protocols\Http\Request)) #4 /www/apiV2/vendor/workerman/workerman/src/Connection/TcpConnection.php(676): Webman\App->onMessage(Object(Workerman\Connection\TcpConnection), Object(Workerman\Protocols\Http\Request)) #5 /www/apiV2/vendor/workerman/workerman/src/Events/Swoole.php(288): Workerman\Connection\TcpConnection->baseRead(Resource id #10242) #6 [internal function]: Workerman\Events\Swoole->Workerman\Events\{closure}() #7 {main}