diff --git a/etc/config/command.php b/etc/config/command.php index 600025cf4..bc8688c21 100644 --- a/etc/config/command.php +++ b/etc/config/command.php @@ -27,17 +27,32 @@ $magentoBinary = $php . ' -f ../../../../bin/magento'; $valid = validateCommand($magentoBinary, $command); if ($valid) { - exec( - escapeCommand($magentoBinary . " $command" . " $arguments") . " 2>&1", - $output, - $exitCode - ); - if ($exitCode == 0) { + $process = new Symfony\Component\Process\Process($magentoBinary . " $command" . " $arguments"); + $process->setIdleTimeout(60); + $process->setTimeout(0); + $idleTimeout = false; + try { + $process->run(); + $output = $process->getOutput(); + if (!$process->isSuccessful()) { + $output = $process->getErrorOutput(); + } + if (empty($output)) { + $output = "CLI did not return output."; + } + + } catch (Symfony\Component\Process\Exception\ProcessTimedOutException $exception) { + $output = "CLI command timed out, no output available."; + $idleTimeout = true; + } + $exitCode = $process->getExitCode(); + + if ($exitCode == 0 || $idleTimeout) { http_response_code(202); } else { http_response_code(500); } - echo implode("\n", $output); + echo $output; } else { http_response_code(403); echo "Given command not found valid in Magento CLI Command list.";