I have a Symfony2 app representing a restful application that has no need for persistent sessions.
For each request to the application, given the default session configuration, and given that the client ignores the session cookie, a new session file is created in the default session save path of app/cache/<env>/sessions.
The app receives many requests per day resulting in a very large volume of unwanted session files. Running rm -Rf app/cache/prod/session/* takes minutes to complete.
I would prefer if the app did not store any session data.
I have tried setting the application configuration session save path to /dev/null or /dev/null/sessions but this results an exception either due to the directory already existing (for /dev/null) or due to the specified path being not a directory (for /dev/null/<anything>).
framework:
session:
save_path: /dev/null
The best I can see I can do from reading the session documentation is to invalidate the session, which clears all session attributes and regenerates the session ID. This doesn’t get me to a state of there being no session and no persistent session file.
Can I get Symfony2 to not store any session data for a request?
You can define your own Session handler and replace
sessionservice alias with it:You can check implementation with standard session class
Symfony\Component\HttpFoundation\Session\Session