1
0
mirror of https://github.com/danog/amp.git synced 2024-11-26 20:15:00 +01:00
amp/examples/event-loop/stdin.php

22 lines
445 B
PHP
Raw Normal View History

2017-05-02 13:32:58 +02:00
#!/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);
2017-05-02 13:32:58 +02:00
exit(1);
}
print "Write something and hit enter" . PHP_EOL;
Loop::onReadable(STDIN, function ($watcher, $stream) {
$chunk = \fread($stream, 8192);
2017-05-02 13:32:58 +02:00
print "Read " . \strlen($chunk) . " bytes" . PHP_EOL;
2017-05-02 13:32:58 +02:00
});
Loop::run();