protected function execute(InputInterface $input, OutputInterface $output)
{
$channels = [];
$maxChannels = $input->getArgument('CPUs');
$exampleArray = $this->getExampleArray();
$output->writeln('<fg=green>Start example process</>');
while (count($exampleArray) > 0 || count($channels) > 0) {
foreach ($channels as $key => $channel) {
if ($channel instanceof Process && $channel->isTerminated()) {
unset($channels[$key]);
}
}
if (count($channels) >= $maxChannels) {
continue;
}
if (!($item = array_pop($exampleArray))) {
continue;
}
$process = new Process(sprintf('php index.php example:sub-process %s', $item), __DIR__ . '/../../../');
$process->start();
if (!$process->isStarted()) {
throw new \Exception($process->getErrorOutput());
}
$channels[] = $process;
}
$output->writeln('<bg=green;fg=black>Done.</>');
}