Running a background task using Symfony Process without having to wait for the process to finish

后端 未结 5 1517
隐瞒了意图╮
隐瞒了意图╮ 2021-02-12 22:30

After a user submits a form, I want to render a view file, and right after that I want to initiate a background task to process five MS Excel files (each may have up to 2000 row

5条回答
  •  深忆病人
    2021-02-12 23:25

    Running Processes Asynchronously

    You can also start the subprocess and then let it run asynchronously, retrieving output and the status in your main process whenever you need it. Use the start() method to start an asynchronous process

    documentation

    so, to start your command asynchronously you should create new process with command and start it

    $process = new Process('php bin/console hello:word');
    $process->start();
    

    Consider to change this to full paths like \usr\bin\php \var\www\html\bin\console hello:word

    Also there is good bundle cocur/background-process you may use it, or at least read the docs to find out how it works.

提交回复
热议问题