0

When I submit my form it reads a file of thousands lines and executes some tasks.
I have created a symfony command to do that.
Once my form is submitted and validated I pass the command the required arguments.
The different tasks are executed but not asynchronously.
I cannot go to another page before the end of the process.

The Symfony controller

<?php
        
namespace App/Controller
        
class FileConfigController  
{
  public function loadFile(KernelInterface $kernel) {
    // ...
    if ($form->isSubmitted() && $form->isValid()) {
     $name = 'Test.xls';

     $application = new Application($kernel);
     $application->setAutoExit(false);
     $application->setCatchExceptions(true);
     $input = new ArrayInput([
      'command' => 'app:load-file',
      'name' = $name,
      'type' = $form['type']->getData()
     ]);
     $application->run($input, new NullOutput());
  }
}

The Symfony command script

<?php
        
namespace App/Command
        
class FileCommand extends Command
{
  protected static $defaultName = 'app:load-file';
            
  protected function configure() {}
        
  protected function execute(InputInterface $input, OutputInterface $output)
  {
     $name = $input->getArgument('name');
     $type = $input->getArgument('type');
    
     // Script
   }
}
MathPi
  • 11
  • 3
  • Does this answer your question? [How to launch a Symfony Command asynchronously during a request using the Symfony Process component?](https://stackoverflow.com/questions/69195529/how-to-launch-a-symfony-command-asynchronously-during-a-request-using-the-symfon) – colonelclick Dec 28 '22 at 17:23

2 Answers2

0

Queue of tasks can unlock you. There are some highlight bundles for it, one of them is symfony messenger bundle

https://symfony.com/doc/current/messenger.html

Fyi, If you really love it, there is the great tutorial about it but it’s not free :D

https://symfonycasts.com/screencast/messenger

To use it effectively, use supervisord to manage processes in the background

http://supervisord.org/

ping
  • 61
  • 4
0

If you want to make async http requests, you can use Guzzle: https://docs.guzzlephp.org/en/stable/index.html.

Thykof
  • 895
  • 7
  • 9