In the Symfony configuration there is an entry framework.session.storage_id
. This setting also appears in the default config on the Symfony configuration documentation but it is not explained. My assumption is that it defines where session data is stored on the server side.
Values I have seen for this entry include session.storage.mock_file
, session.storage.native
and session.storage.filesystem
. I am unsure of what these values exactly mean (e.g. what is the difference between a mock file and a filesystem?) and also think that this is not the complete list of possible values.
So what exactly does this configuration key control and what values are valid?
Valid values for framework.session.storage_id
are following:
session.storage.mock_file
- for testing. It doesn't start session at all.session.storage.filesystem
- for testing. It is an alias for session.storage.mock_file
.session.storage.native
- default implementation using defined session handlersession.storage.php_bridge
- for legacy apps
From developer perspective, there is a session
service that abstracts working with session. session
service depends on some session storage service. Session storage implements session management from PHP perspective (calling session_start()
function for example). Storage also depends on some session handler. Handler is implementation of \SessionStorage
and it tells how and where will be session physically stored.
This three layer design allows creating storage for testing which does not call session_start()
at all and does not use handler (session.storage.mock_file
). Or creating of handler that can store and load session from anywhere (session.storage.native
). session.storage.php_bridge
solves situation when session_start()
is called by external PHP code (not by Symfony session storage).
I hope it is clear to understand.
Session management in Symfony is based on two main rules.
session_*()
and $_SESSION
global.However, some exceptions exist. Sometimes it may be necessary to integrate Symfony in a legacy application, which starts the session with session_start()
.
With session.storage.php_bridge
directive, you can manage the session using a special gateway that is designed to allow to Symfony working with a session that was started outside the framework.
In goal to make the code using sessions testable, session.storage.mock_file
directive allows to simulate the flow of a PHP session without starting it really.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With