On a Symfony 5.4 application running with PHP 8.1, the default configuration for sessions is as follows:
# config/packages/framework.yaml
framework:
session:
handler_id: null
cookie_secure: auto
cookie_samesite: lax
storage_factory_id: session.storage.factory.native
It relies on the native PHP session management. Being on a Debian system, session files are stored in /var/lib/php/sessions/
and expired sessions are natively handled with a dedicated cleaner service (process known as garbage collection).
If you change the save_path
option for another folder as stated in the doc, the configuration becomes:
# config/packages/framework.yaml
framework:
session:
handler_id: 'session.handler.native_file'
save_path: '%kernel.project_dir%/var/sessions/%kernel.environment%'
cookie_secure: auto
cookie_samesite: lax
storage_factory_id: session.storage.factory.native
Now, garbage collection does not work anymore and session files are stacking in the target folder. Yet, I thought that Symfony would have made a call to SessionHandler::gc
.
Does this mean that Symfony does not support session cleaning by itself?