1
0
mirror of https://github.com/danog/amp.git synced 2024-12-11 17:09:40 +01:00
amp/examples/event-loop/stdin.php
2017-11-29 13:36:50 +01:00

22 lines
445 B
PHP

#!/usr/bin/env php
<?php
require __DIR__ . '/../../vendor/autoload.php';
use Amp\Loop;
if (\stream_set_blocking(STDIN, false) !== true) {
\fwrite(STDERR, "Unable to set STDIN to non-blocking" . PHP_EOL);
exit(1);
}
print "Write something and hit enter" . PHP_EOL;
Loop::onReadable(STDIN, function ($watcher, $stream) {
$chunk = \fread($stream, 8192);
print "Read " . \strlen($chunk) . " bytes" . PHP_EOL;
});
Loop::run();