Swoole Hook STDIO

The SWOOLE_HOOK_STDIO flag will enable coroutine support for PHP standard IO. Support was added in v4.6.2.

More information on PHP STDIO can be found here.

Example

<?php

use Swoole\Process;

Co::set(['socket_read_timeout' => -1, 'hook_flags' => SWOOLE_HOOK_STDIO]);

$proc = new Process(function ($p) {

    Co\run(function () use($p) {

        $p->write('start'.PHP_EOL);

        go(function() {

            co::sleep(0.05);
            echo "sleep\n";

        });

        echo fread(STDIN, 1024);
    });

}, true, SOCK_STREAM);

$proc->start();

echo $proc->read();

usleep(100000);

$proc->write('hello world'.PHP_EOL);

echo $proc->read();
echo $proc->read();

Process::wait();