Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are valid values for framework.session.storage_id?

Tags:

config

symfony

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?

like image 652
Chris Avatar asked Apr 10 '15 10:04

Chris


Video Answer


2 Answers

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 handler
  • session.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.

like image 96
kba Avatar answered Oct 24 '22 11:10

kba


Session management in Symfony is based on two main rules.

  1. Symfony must start the session.
  2. The Symfony sessions are designed to replace the use of PHP native functions 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.

like image 31
Icham Avatar answered Oct 24 '22 13:10

Icham