OpenSwoole Hook File

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


Latest version: pecl install openswoole-26.2.0

The OpenSwoole\Runtime::HOOK_FILE flag will enable coroutine support for native PHP file operation functions. Support was added in OpenSwoole v4.3.0.

This includes support for:

  • fopen
  • fread and fgets
  • fwrite and fputs
  • file_get_contents and file_put_contents
  • unlink
  • mkdir
  • rmdir

Example

<?php

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

Co::run(function()
{
    $fp = fopen("test.log", "a+");
    fwrite($fp, str_repeat('A', 2048));
    fwrite($fp, str_repeat('B', 2048));
});
Last updated on February 28, 2026