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

后端 未结 5 1529
隐瞒了意图╮
隐瞒了意图╮ 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:18

    For using in controller:

    use Symfony\Component\HttpKernel\KernelEvents;
    use Symfony\Component\HttpKernel\Event\PostResponseEvent;
    
    $myVar = new MyObject();
    $this->get('event_dispatcher')->addListener(KernelEvents::TERMINATE, function(PostResponseEvent $event) use($myVar) {
        //You logic here
        $request = $event->getRequest();
        $test = $myVar->getMyStuff();
    });
    

    But it is not a good practice, please read about normal registering event listeners

    kernel.terminate event will be dispatched after sending the response to user.

提交回复
热议问题