webman2.1开启协程上下文传输时报错

guchen

问题描述

webman2.1 使用了swoole作为驱动
在测试协程上下文传输时报错
截图

程序代码或配置

截图

操作系统环境及workerman/webman等具体版本

截图
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"
185 3 0
3个回答

发下 config/process.php

  • walkor 3天前

    贴全,包括命名空间

  • guchen 3天前

    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类,正常应该使用support/Request
调用栈里看到使用的是 Workerman\Protocols\Http\Request
类是在 config/process.php 里的 requestClass 指定的,可能你改了什么东西,用了错误的Request类。

  • guchen 3天前

    检查了一下,我控制器业务代码里引用的就是 use support\Request;这个问题我重启容器后又好了QWQ

  • walkor 3天前

    类是在 config/process.php 里的 requestClass 指定的,可能之前配置是错的

  • guchen 3天前

    老大 应该不是这个问题 这个情况又复现了 经常出现这种情况

  • guchen 3天前

    项目是新起的 基本只写了几个测试的接口

  • walkor 3天前

    写一个能稳定复现的例子,打包发到我邮箱 walkor@workerman.net
    写明重现步骤。主要,要能重现问题的例子。

guchen
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}
  • 暂无评论
×
🔝