OpenSwoole Hook Blocking Function

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


Latest version: pecl install openswoole-26.2.0

The OpenSwoole\Runtime::HOOK_BLOCKING_FUNCTION flag will enable coroutine support for blocking PHP functions. Support was added in OpenSwoole v4.4.0.

You have to install OpenSwoole core library with composer require openswoole\core to use this hook.

This includes support for:

  • gethostbyname
  • exec
  • shell_exec

Example

<?php

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

co::run(function()
{
    echo shell_exec('ls');
});
Last updated on February 28, 2026