2017-05-02 13:32:58 +02:00
|
|
|
#!/usr/bin/env php
|
|
|
|
<?php
|
|
|
|
|
|
|
|
require __DIR__ . '/../../vendor/autoload.php';
|
|
|
|
|
|
|
|
use Amp\Loop;
|
|
|
|
|
2017-11-29 13:36:50 +01:00
|
|
|
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) {
|
2017-11-29 13:36:50 +01:00
|
|
|
$chunk = \fread($stream, 8192);
|
2017-05-02 13:32:58 +02:00
|
|
|
|
2017-11-29 13:36:50 +01:00
|
|
|
print "Read " . \strlen($chunk) . " bytes" . PHP_EOL;
|
2017-05-02 13:32:58 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
Loop::run();
|