Skip to content

Commit

Permalink
Simplify ping-many example
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Jan 9, 2023
1 parent 423bda2 commit 9c9247f
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions examples/ping-many.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,20 @@
use Amp\Future;
use Amp\Process\Process;
use function Amp\async;
use function Amp\ByteStream\getStdout;

function show_process_output(Process $process): void
{
$stream = $process->getStdout();

while (null !== $chunk = $stream->read()) {
echo $chunk;
}
Amp\ByteStream\pipe($process->getStdout(), getStdout());

$code = $process->join();
$pid = $process->getPid();

echo "Process {$pid} exited with {$code}\n";
getStdout()->write("Process {$pid} exited with {$code}\n");
}

$hosts = ['8.8.8.8', '8.8.4.4', 'google.com', 'stackoverflow.com', 'github.com'];

$futures = [];

foreach ($hosts as $host) {
foreach (['8.8.8.8', '8.8.4.4', 'google.com', 'stackoverflow.com', 'github.com'] as $host) {
$command = \DIRECTORY_SEPARATOR === "\\"
? "ping -n 5 {$host}"
: "ping -c 5 {$host}";
Expand Down

0 comments on commit 9c9247f

Please sign in to comment.