1
0
mirror of https://github.com/danog/process.git synced 2024-11-30 04:39:04 +01:00
process/examples/watch-live.php
Aaron Piotrowski 91dc2ec100
Update examples
2018-10-15 09:55:15 -05:00

24 lines
680 B
PHP

<?php
include \dirname(__DIR__) . "/vendor/autoload.php";
use Amp\Process\Process;
Amp\Loop::run(function () {
// abuse ping for sleep, see https://stackoverflow.com/a/1672349/2373138
$command = \DIRECTORY_SEPARATOR === "\\"
? "cmd /c echo 1 & ping -n 2 127.0.0.1 > nul & echo 2 & ping -n 2 127.0.0.1 > nul & echo 3 & exit 42"
: "echo 1; sleep 1; echo 2; sleep 1; echo 3; exit 42";
$process = new Process($command);
yield $process->start();
$stream = $process->getStdout();
while (null !== $chunk = yield $stream->read()) {
echo $chunk;
}
$code = yield $process->join();
echo "Process exited with {$code}.\n";
});