<?php
Swoole\Coroutine\System::waitEvent(mixed $resource, int $events = SWOOLE_EVENT_READ, float $timeout = -1): int | false
Resource such as a socket or fd, sockets
, php_stream
, Swoole\Client
, Swoole\Process
, Swoole\Coroutine\Client
, fd
.
SWOOLE_EVENT_READ
, SWOOLE_EVENT_WRITE
, or SWOOLE_EVENT_WRITE | SWOOLE_EVENT_READ
Waiting timeout.
Wait for the I\O event witin coroutine context.
<?php
Co\run(function () {
$stdin = fopen("php://stdin", 'r');
$ip = Swoole\Coroutine\System::waitEvent($stdin, SWOOLE_EVENT_READ, 5);
if ($ip) {
echo fgets($stdin);
} else {
echo "timeout\n";
}
});