Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

symfony code after returning response

Tags:

php

symfony

I want to return the final user a response, before I'm making all the hard processing data.

I want to simply get a request from user, return a response, it could be a simple json,

and than the user will see the data, but in my server side I would continue my rest of the processing, calling analytics, changing DB and other.

something like this idea: continue processing php after sending http response

like image 938
Tzook Bar Noy Avatar asked Oct 15 '25 00:10

Tzook Bar Noy


2 Answers

For heavier tasks you should use the kernel.terminate Event. So any task in this event is performed, after the response was sent. This is the way, how the swiftmailer memory spool works.

like image 175
Emii Khaos Avatar answered Oct 17 '25 14:10

Emii Khaos


This maybe a late answer, but the mentioned scenario makes a perfect use of Queues. Using a library like LeezyPheanstalkBundle will make usage of beanstalkd a lot easier.

What happens is:
1. Receive user request
2. Add job to queue (very fast)
3. Return server response
4. a worker retrieve the job and processes it.

like image 31
Nagy Wesley Avatar answered Oct 17 '25 14:10

Nagy Wesley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!