0

I would like to run a process on my controller and while the process is running my twig page should be shown.

Here is my code:

$cmd="my command ";
$process = new Process('');
$process->setCommandLine($cmd);

return $this->render('sendForm.html.twig');

$process->start();
Brydenr
  • 798
  • 1
  • 19
  • 30
  • Well for starters you have the return statement before you actually start your process. – Martin M. Jun 15 '20 at 13:37
  • so i did put the return after but don't work too – OQuimbamba Jun 15 '20 at 13:39
  • Did you also read [this](https://symfony.com/doc/current/components/process.html)? – Martin M. Jun 15 '20 at 13:41
  • i did use it but the but the server kill me process before end – OQuimbamba Jun 15 '20 at 13:45
  • 3
    This is generally a bad idea. Use something else to decouple the processes. Just store the job you wan to run, and cron job or something like that to consume the pending tasks. Symfony has Messenger which is perfectly suited for this, but the logic is the same: store the "task" in some sort of queue, and have a different processes execute the pending tasks. – yivi Jun 15 '20 at 13:55
  • You can use EventSubscriber or EventListener for that. Check https://stackoverflow.com/questions/35219537/symfony-run-code-after-response-was-sent – Julien B. Jun 15 '20 at 14:13

0 Answers0