Symfony2 runs a console command in the background

I created a console command for my symfony2 project, and I want to execute it from the controller without blocking the controller output (in the background).

Usually done as follows:

$application = new Application($kernel);
$application->setAutoExit(true);

// AppBundle/Command/UpdateStockCommand.php
      $input = new ArrayInput(array(
          'command' => 'update:stock',
        ));

$output = new NullOutput();
$application->run($input, $output);

But, working this way, the user will have to wait for the completion of the task, which may take several minutes.

Decision:

$kernel = $this->get('kernel');
$process = new \Symfony\Component\Process\Process('nohup php '. $kernel->getRootDir() .'/console update:stock --env='. $kernel->getEnvironment() .' > /dev/null 2>&1 &');
//$process->start();
$process->run();

No errors, the controller displays the output, but the task does not complete.

Another solution:

exec('/usr/bin/php '.$this->get('kernel')->getRootDir().'/console update:stock --env=dev > /dev/null 2>&1 &');

found here Symfony2 - running the symfony2 command , but does not work on my example.

+4
source share
1 answer

Hierarchical processes

All processes in the system have their own hierarchical structure.

: Process A, Process B. Process A, Process B , Process B Process A.

(http) Apache PHP- stdoutput ( Nginx + PHPFPM - ). ( Symfony/Process library) apache fpm. ( apache nginx) ( PHP-).

:

P.S.

RabbitMQ.

+2

All Articles