2017-01-11 19:24:02 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
include dirname(__DIR__) . "/vendor/autoload.php";
|
|
|
|
|
2017-01-15 16:30:34 +01:00
|
|
|
use Amp\Process\StreamedProcess;
|
2017-01-11 19:24:02 +01:00
|
|
|
|
|
|
|
AsyncInterop\Loop::execute(\Amp\wrap(function() {
|
|
|
|
$process = new StreamedProcess("echo 1; sleep 1; echo 2; sleep 1; echo 3");
|
2017-01-15 16:30:34 +01:00
|
|
|
$promise = $process->execute();
|
2017-01-11 19:24:02 +01:00
|
|
|
|
2017-01-15 16:30:34 +01:00
|
|
|
$stdout = $process->getStdout();
|
2017-01-11 19:24:02 +01:00
|
|
|
|
2017-01-15 16:30:34 +01:00
|
|
|
while (yield $stdout->advance()) {
|
|
|
|
echo $stdout->getCurrent();
|
2017-01-11 19:24:02 +01:00
|
|
|
}
|
|
|
|
|
2017-01-15 16:30:34 +01:00
|
|
|
$code = yield $promise;
|
|
|
|
echo "Process exited with {$code}.\n";
|
2017-01-11 19:24:02 +01:00
|
|
|
}));
|