Swoole Hook UDG

Notice: the documentation is suitable for PHP extension swoole until v4.7.1, we only support PHP extension openswoole from v4.7.1

The SWOOLE_HOOK_UDG flag will enable coroutine support for Unix Dgram sockets and streams. Support was added in v4.2.0.

Example

<?php

Co::set(['hook_flags' => SWOOLE_HOOK_UDG]);

Co\run(function()
{
    $socket = stream_socket_server(
        'udg://swoole.sock',
        $errno,
        $errstr,
        STREAM_SERVER_BIND
    );

    if(!$socket)
    {
        echo "$errstr ($errno)" . PHP_EOL;
        exit(1);
    }

    while(stream_socket_recvfrom($socket, 1, 0))
    {
        // ...
    }
});