OpenSwoole Hook Unix

25.x is outdated, please check the latest version 26.x


Latest version: pecl install openswoole-26.2.0

The OpenSwoole\Runtime::HOOK_UNIX flag will enable coroutine support for Unix Stream Sockets. Support began from OpenSwoole v4.2.0.

Example

<?php

Co::set(['hook_flags' => OpenSwoole\Runtime::HOOK_UNIX]);

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

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

    while(stream_socket_accept($socket))
    {
        // ...
    }
});
Last updated on February 28, 2026