1
0
mirror of https://github.com/danog/process.git synced 2025-01-23 06:11:34 +01:00
process/examples/003_watch_live.php
Bob Weinand d2da56638f Fixup after PR #5, add some more tests
Also removing status() again
2015-09-16 19:56:15 +02:00

22 lines
615 B
PHP

<?php
use Amp\Process;
include __DIR__."/../vendor/autoload.php";
\Amp\run(function() {
$proc = new Process("echo 1; sleep 1; echo 2; sleep 1; echo 3");
$promise = $proc->exec();
$promise->watch(function($data) {
// $data[0] is either "out" or "err", $data[1] the actual data
list($type, $msg) = $data;
// "1" ... 2 seconds ... "2" ... 2 seconds ... "3"
print "$type: $msg";
});
$result = (yield $promise);
// we aren't buffering by default (Process::BUFFER_NONE is default) ... so only exit code present and eventually the killing signal
var_dump($result);
});