Coroutine Library

Coroutine Library

Swoole Library is a group of Swoole Coroutine build-in functions implmeneted with PHP.

Swoole\Coroutine\WaitGroup

Swoole\Coroutine\Barrier

Swoole\Coroutine\Batch

Swoole\Coroutine\map

Swoole\ConnectionPool

Swoole\Database\PDOPool

Swoole\Database\MySQLiPool

Swoole\Database\RedisPool


Swoole Coroutine Server

Coroutine TCP Server can be created dynamically and used in Coroutine context. The methods and features are the same as Swoole\Server.

Example

<?php
declare(strict_types=1);

use Swoole\Coroutine\Server;
use Swoole\Coroutine\Server\Connection;
go(function () {
    $server = new Server('0.0.0.0', 9601, false);
    $server->handle(function (Connection $conn) use ($server) {
        while('' !== $data = $conn->recv()) {
            $json = json_decode($data, true);
            if(is_array($json) && 'hello' === $json['data']) {
                $conn->send("world\n");
            }
        }
        echo 'disconnected', PHP_EOL;
    });
    $server->start();
});