From 423b0074046b3927b35b93b44dcb4dc18b44807d Mon Sep 17 00:00:00 2001 From: Kevin Kozan Date: Wed, 13 Feb 2019 13:19:32 -0600 Subject: [PATCH] MQE-1444: Allow MagentoCLI to bypass wait for process - Implemented timeout logic to CLI command --- etc/config/command.php | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) 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.";