Workerman/Coroutine/Coroutine 如何正确开启携程?

Youfeed

新版本如何正确开启携程

每次报这个错误?
Error: Class "Workerman\Coroutine\Coroutine" not found

config\server.php 的配置

return [
    'event_loop' => Workerman\Events\Fiber::class, // 这里配置会报错
    'stop_timeout' => 2,
    'pid_file' => runtime_path() . '/webman.pid',
    'status_file' => runtime_path() . '/webman.status',
    'stdout_file' => runtime_path() . '/logs/stdout.log',
    'log_file' => runtime_path() . '/logs/workerman.log',
    'max_package_size' => 10 * 1024 * 1024
];

config\process.php 的配置

return [
    'webman' => [
        'handler' => Http::class,
        'listen' => 'http://0.0.0.0:274',
        'count' => cpu_count() * 4,
        'user' => '',
        'group' => '',
        'reusePort' => false,
        'eventLoop' => '',//\Workerman\Events\Fiber::class,
        'context' => [],
        'constructor' => [
            'requestClass' => Request::class,
            'logger' => Log::channel('default'),
            'appPath' => app_path(),
            'publicPath' => public_path()
        ]
    ],
    ...
]

报错信息

`Error: Class "Workerman\Coroutine\Coroutine" not found` in "/vendor/workerman/workerman/src/Worker.php:2651
match (Worker::$eventLoopClass) {
    Swoole::class,
    Swow::class,
    Fiber::class => Coroutine::create($callback), // 2651 是这一行

    default => (new \Fiber($callback))->start(),
};

composer.json

  "require": {
    "php": ">=8.1",
    "workerman/workerman": "~5.1",
    "workerman/webman-framework": "~2.1",
    "workerman/http-client": "^3.0",
    "revolt/event-loop": "^1.0", // 
    "monolog/monolog": "^2.0",
    "webman/database": "^2.1",
    "webman/redis": "^2.1",
    "illuminate/pagination": "^10.49",
    "illuminate/events": "^10.49",
    "youloge/ini": "^1.3",
    "youloge/webman.validate": "^1.4"
  },
223 2 1
2个回答

nitron
安装了swoole或者swow扩展,或者安装了composer require revolt/event-loop (Fiber)

更新到 ^5.1.6试下, composer require workerman/workerman ^5.1.6

🔝