Swoole Hook Blocking Function

Notice: ext-swoole is supported until v4.7.1, use ext-openswoole >= v4.7.1. Latest version: pecl install openswoole-4.9.1

The SWOOLE_HOOK_BLOCKING_FUNCTION flag will enable coroutine support for blocking PHP functions. Support was added in v4.4.0.

This includes support for:

  • gethostbyname
  • exec
  • shell_exec

Example

<?php

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

Co\run(function()
{
    echo shell_exec('ls');
});