Skip to content

Instantly share code, notes, and snippets.

@dalailomo
Created May 25, 2017 16:18
Show Gist options
  • Save dalailomo/9f411e2d7adfb5c5c2b25dbd2cefc82d to your computer and use it in GitHub Desktop.
Save dalailomo/9f411e2d7adfb5c5c2b25dbd2cefc82d to your computer and use it in GitHub Desktop.
reactphp async child processes
<?php
require 'vendor/autoload.php';
function notify($output, $command)
{
echo <<<EOF
"$command":
---------------------------------------
$output
EOF;
}
$commands = [
'find ~/ -name "aprocess.php"',
'find ~/ -name "paj1.gif"',
'find ~/ -name ".myNotes.md"',
'find ~/ -name "*.gif"',
];
$loop = React\EventLoop\Factory::create();
array_map(function ($command) use ($loop) {
$process = new React\ChildProcess\Process($command);
$process->start($loop);
$process->stdout->on('data', function ($output) use ($command) {
notify($output, $command);
});
$process->stderr->on('data', function ($output) use ($command) {
notify("ERROR [" . $output . "]", $command);
});
}, $commands);
$loop->run();
{
"require": {
"react/react": "^0.4.2",
"react/child-process": "^0.4.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment