Neos\Flow\Core\Booting\Scripts::executeCommand PHP Method

executeCommand() public static method

Executes the given command as a sub-request to the Flow CLI system.
public static executeCommand ( string $commandIdentifier, array $settings, boolean $outputResults = true, array $commandArguments = [] ) : boolean
$commandIdentifier string E.g. neos.flow:cache:flush
$settings array The Neos.Flow settings
$outputResults boolean if FALSE the output of this command is only echoed if the execution was not successful
$commandArguments array Command arguments
return boolean TRUE if the command execution was successful (exit code = 0)
    public static function executeCommand($commandIdentifier, array $settings, $outputResults = true, array $commandArguments = [])
    {
        $command = self::buildSubprocessCommand($commandIdentifier, $settings, $commandArguments);
        $output = [];
        // Output errors in response
        $command .= ' 2>&1';
        exec($command, $output, $result);
        if ($result !== 0) {
            if (count($output) > 0) {
                $exceptionMessage = implode(PHP_EOL, $output);
            } else {
                $exceptionMessage = sprintf('Execution of subprocess failed with exit code %d without any further output. (Please check your PHP error log for possible Fatal errors)', $result);
            }
            throw new Exception\SubProcessException($exceptionMessage, 1355480641);
        }
        if ($outputResults) {
            echo implode(PHP_EOL, $output);
        }
        return $result === 0;
    }

Usage Example

Example #1
0
 /**
  * @inheritdoc
  */
 public function submit($payload, array $options = [])
 {
     $messageId = Algorithms::generateUUID();
     $message = new Message($messageId, $payload);
     $commandArguments = [$this->name, base64_encode(serialize($message))];
     if ($this->async) {
         if (!method_exists(Scripts::class, 'executeCommandAsync')) {
             throw new \RuntimeException('The "async" flag is set, but the currently used Flow version doesn\'t support this (Flow 3.3+ is required)', 1469116604);
         }
         Scripts::executeCommandAsync('flowpack.jobqueue.common:job:execute', $this->flowSettings, $commandArguments);
     } else {
         Scripts::executeCommand('flowpack.jobqueue.common:job:execute', $this->flowSettings, true, $commandArguments);
     }
     return $messageId;
 }
All Usage Examples Of Neos\Flow\Core\Booting\Scripts::executeCommand