1
0
mirror of https://github.com/danog/amp.git synced 2024-11-30 04:29:08 +01:00

Add signal and stdin examples

This commit is contained in:
Niklas Keller 2017-05-02 13:32:58 +02:00
parent 2a5600f027
commit 1b1ea5688c
2 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,15 @@
#!/usr/bin/env php
<?php
require __DIR__ . '/../../vendor/autoload.php';
use Amp\Loop;
print "Press Ctrl+C to exit..." . PHP_EOL;
Loop::onSignal(SIGINT, function () {
print "Caught SIGINT, exiting..." . PHP_EOL;
exit(0);
});
Loop::run();

21
examples/basic/stdin.php Normal file
View File

@ -0,0 +1,21 @@
#!/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();