walkor / workerman

An asynchronous event driven PHP socket framework. Supports HTTP, Websocket, SSL and other custom protocols.
http://www.workerman.net
MIT License
11.12k stars 2.26k forks source link

Using Swoole's eventLoopClass #720

Open cayolblake opened 2 years ago

cayolblake commented 2 years ago

Hello @walkor

What is exactly happening when I set $eventLoopClass to Workerman\Events\Swoole and use the following in onMessage? How come Swoole's coroutines working without issues ?! 🤔

$http_worker->onMessage = function ($connection, $request) {
            Co\run(function()
            {
                swoole_coroutine_create(function()
                {
                    Co::sleep(1);
                    echo "Done 1\n";
                });

                swoole_coroutine_create(function()
                {
                    Co::sleep(1);
                    echo "Done 2\n";
                });
            });

    // Send data to client
    $connection->send("Hello World");
};
walkor commented 2 years ago

Swoole provides an event loop interface, which is universal. workerman can use the functions of swoole after adapting this interface.