The PHP Function Fastcgi_Finish_Request
The php function fastcgi_finish_request is a great way to allow your PHP script to continue running after the HTTP response has been sent back to the client. This is especially useful if you need to run some time consuming task (like sending e-mails or processing stats) and do not want your web server to stop responding to requests.
However, there are some pitfalls to be aware of. The most important one is that your script will still occupy an FPM process after calling fastcgi_finish_request. This may lead to a dog-piling of your PHP-FPM processes which can cause gateway errors on the webserver.
If you use this method in a Symfony application and also rely on the session handling in your application, it is crucial to call the session_write_close() function immediately after the php script has called fastcgi_finish_request(). Otherwise, sessions are locked as long as the php script is alive which will prevent subsequent requests from being served and your users will experience a slow page load.
In my opinion, it is better to use a dedicated queue/server for processing background tasks rather than hacking this type of functionality into your application. A lot of different solutions exist for this such as using pseudo cron jobs, using library like RabbitMQ or Laravel Queues. However, I understand that this approach is not feasible for a lot of projects, especially if you only have limited resources. Therefore, php function fastcgi_finish_request can be very helpful and I strongly recommend that you take advantage of it.