OpenSwoole Hook UDG

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

The OpenSwoole\Runtime::HOOK_UDG flag will enable coroutine support for Unix Dgram sockets and streams. Support was added in OpenSwoole v4.2.0.

Example

<?php

co::set(['hook_flags' => OpenSwoole\Runtime::HOOK_UDG]);

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

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

    while(stream_socket_recvfrom($socket, 1, 0))
    {
        // ...
    }
});
Last updated on September 21, 2022