SaveSessionListener

SaveSessionListener

class SaveSessionListener implements EventSubscriberInterface

Saves the session, in case it is still open, before sending the response/headers.

This ensures several things in case the developer did not save the session explicitly:

  • If a session save handler without locking is used, it ensures the data is available on the next request, e.g. after a redirect. PHPs auto-save at script end via sessionregistershutdown is executed after fastcgifinishrequest. So in this case the data could be missing the next request because it might not be saved the moment the new request is processed.
  • A locking save handler (e.g. the native 'files') circumvents concurrency problems like the one above.