logger = $logger; $this->kernel = $kernel; if (null !== $timeout) { $this->timeout = $timeout; } } public function run(CommandMessage $message): void { $phpBinaryPath = (new PhpExecutableFinder)->find(); $consoleCommand = [ 'php' => $phpBinaryPath ?: 'php', 'console' => sprintf('%s/bin/console', $this->kernel->getContainer()->getParameter('kernel.project_dir')), 'command' => $message->getCommandName() ]; $process = new Process( array_merge( array_values($consoleCommand), array_values($message->getArguments()), array_values($this->getOptions($message)), ) ); try { $process ->setTimeout($this->timeout) ->run(static function(string $type, string $buffer) { echo $buffer; }) ; } catch (ProcessTimedOutException $processTimedOutException) { $this->logger->error( sprintf( 'Process "%s" killed after %d seconds of execution', $processTimedOutException->getProcess()->getCommandLine(), $processTimedOutException->getProcess()->getTimeout() ) ); } } private function getOptions(CommandMessage $message): array { $options = []; foreach ($message->getFormattedOptions() as $option => $value) { $options[] = $option . '=' . $value; } return $options; } }