Enabling Fiber, Swoole, and Swow Coroutines in Webman 5: Installation, Configuration, and Usage

This guide explains Webman 5's support for Fiber, Swoole, and Swow coroutine drivers, shows how to install the required packages, configure each worker to use a specific driver, provides complete PHP code examples for Workerman and Webman, demonstrates starting the server, checking its status, and highlights compatibility constraints between Swow and Swoole.

Open Source Tech Hub
Open Source Tech Hub
Open Source Tech Hub
Enabling Fiber, Swoole, and Swow Coroutines in Webman 5: Installation, Configuration, and Usage

V5 Features Overview

Supports Fiber coroutine

Supports Swoole coroutine

Supports Swow coroutine

Note

Fiber, Swoole and Swow coroutines cannot coexist in the same worker; only one driver may be used per worker.

Different workers can be configured with different coroutine drivers.

This section demonstrates how Webman can run multiple coroutine‑driven workers by assigning different drivers to each worker.

Fiber Coroutine

composer require revolt/event-loop

Usage in Workerman

<?php
use Workerman\Connection\TcpConnection;
use Workerman\Protocols\Http\Request;
use Workerman\Worker;
require_once __DIR__ . '/vendor/autoload.php';

$worker = new Worker('http://0.0.0.0:8888');
$worker->eventLoop = \Workerman\Events\Revolt::class;
$worker->onMessage = function (TcpConnection $connection, Request $request) {
    $connection->send('hello workerman');
};

Worker::runAll();
?>

Usage in Webman

After installing Webman, the framework automatically switches the event loop to revolt/event-loop when Fiber coroutine is selected.

Start Webman Example

Workerman[start.php] start in DEBUG mode
------------------------------------------------ WORKERMAN -------------------------------------------------
Workerman/5.0.0   PHP/8.3.15 (Jit off)   Linux/5.10.102.1-microsoft-standard-WSL2
------------------------------------------------ WORKERS --------------------------------------------------
event-loop  proto  user  worker   listen               count  state
revolt      tcp    root  webman   http://0.0.0.0:8288   8     [OK]
revolt      tcp    root  monitor  none                 1     [OK]

Swoole Coroutine

Installation guide:

https://wiki.swoole.com/zh-cn/#/environment

Check Swoole Version

pecl info swoole

About pecl.php.net/swoole-6.0.0
-------------------------------
Name: swoole
Channel: pecl.php.net
Release Date: 2024-12-16 08:02:22
Release Version: 6.0.0 (stable)
API Version: 6.0 (stable)
License: Apache2.0
Required PHP version: 8.1.0

Swoole Coroutine Service

The file SwooleCoroutine.php runs a coroutine task every three seconds.

<?php
declare(strict_types=1);

namespace app\common\coroutine;

use Workerman\Crontab\Crontab;

class SwooleCoroutine
{
    public function onWorkerStart(): void
    {
        // Execute every 3 seconds
        new Crontab('*/3 * * * * *', function () {
            $this->execCoroutineTask();
        });
    }

    private function execCoroutineTask(): void
    {
        echo "[x] Swoole Coroutine starts task
";
        // go() is Swoole's coroutine starter
        go('task1');
        go('task2');
        go('task3');
    }
}
?>
The go function creates a new Swoole coroutine.

Coroutine Pseudocode

function task1(): void {
    for ($i = 0; $i <= 5; $i++) {
        usleep(3000); // simulate file write (~3000µs)
        echo "[x] [write file] [$i] " . date('Y-m-d H:i:s') . "
";
        \Co::sleep(0.001); // suspend 1ms, switch coroutine
    }
}

function task2(): void {
    for ($i = 0; $i <= 10; $i++) {
        usleep(3000); // simulate sending mail (~3000µs)
        echo "[x] [send mail] [$i] " . date('Y-m-d H:i:s') . "
";
        \Co::sleep(0.001);
    }
}

function task3(): void {
    for ($i = 0; $i <= 15; $i++) {
        usleep(3000); // simulate inserting rows (~3000µs)
        echo "[x] [insert data] [$i] " . date('Y-m-d H:i:s') . "
";
        \Co::sleep(0.001);
    }
}
Add the following configuration to config/process.php to enable the service:
'swoole-coroutine' => [
    'handler'   => \app\common\coroutine\SwooleCoroutine::class,
    'eventLoop' => \Workerman\Events\Swoole::class,
],

Configuration Explanation handler specifies the process class ( \app\common\coroutine\SwooleCoroutine::class). eventLoop specifies the event‑loop implementation ( \Workerman\Events\Swoole::class).

Start Webman with Swoole Coroutine

$ php start.php start
Workerman[start.php] start in DEBUG mode
------------------------------------------------ WORKERMAN -------------------------------------------------
Workerman/5.0.0   PHP/8.3.15 (Jit off)   Linux/5.10.102.1-microsoft-standard-WSL2
------------------------------------------------ WORKERS --------------------------------------------------
event-loop  proto  user  worker          listen               count  state
revolt      tcp    root  webman          http://0.0.0.0:8288   8     [OK]
swoole      tcp    root  swoole-coroutine none                8     [OK]

Check Webman Service Status

$ php start.php status
Workerman[start.php] status
Start worker in DEBUG mode.
---------------------------------------------------GLOBAL STATUS---------------------------------------------------
Workerman/5.0.0   PHP/8.3.15 (Jit off)   Linux/5.10.102.1-microsoft-standard-WSL2
start time:2025-01-03 22:55:23   run 0 days 0 hours   load average: 1.73, 0.79, 0.77
3 workers   17 processes
name            event-loop   exit_status   exit_count
webman          revolt       0            0
swoole-coroutine swoole       0            0
monitor         revolt       0            0

Swow Extension

composer require swow/swow
Note: Swow and Swoole provide similar functionality and cannot be enabled simultaneously; loading both results in a PHP warning and fatal error.
PHP Warning: Swow is incompatible with Swoole because both provide similar functionality through different implementations.
PHP Fatal error: Unable to start Swow module

References

https://mp.weixin.qq.com/s?__biz=MzUzMDMxNTQ4Nw==&mid=2247492324&idx=1&sn=ac697103fe56d6054593ae6d1bdadb93&scene=21#wechat_redirect
https://mp.weixin.qq.com/s?__biz=MzUzMDMxNTQ4Nw==&mid=2247496493&idx=1&sn=4ab95befc894d556eac26d405f354a40&scene=21#wechat_redirect
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PHPCoroutinesFiberSwooleSwowWebman
Open Source Tech Hub
Written by

Open Source Tech Hub

Sharing cutting-edge internet technologies and practical AI resources.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.