I have an action in Symfony2 controller that is sending out a response back to the client (as detailed here). After the function sends out the response, I have an event subscriber that listens for onkernelTerminate event since I'll be doing some heavy work after the response is sent to the client.
Everything seems to be working normally for the part that's doing the heavy work except that there's line in the code that is referencing a service that utilizes Session, which needs it for storing tokens and eventually communicating with an external API.
The error is of course: Failed to start the session because headers have already been sent.
Is there a way to start a Session even headers have been sent? Or what would be a better approach to handle this issue?