Bridge a legacy Application with Symfony Sessions
Warning: You are browsing the documentation for Symfony 4.x, which is no longer maintained.
Consider upgrading your projects to Symfony 7.2.
If you're integrating the Symfony full-stack Framework into a legacy application
that starts the session with session_start()
, you may still be able to
use Symfony's session management by using the PHP Bridge session.
If the application has its own PHP save handler, you can specify null
for the handler_id
:
1 2 3 4 5
# config/packages/framework.yaml
framework:
session:
storage_id: session.storage.php_bridge
handler_id: ~
Otherwise, if the problem is that you cannot avoid the application
starting the session with session_start()
, you can still make use of
a Symfony based session save handler by specifying the save handler as in
the example below:
1 2 3 4 5
# config/packages/framework.yaml
framework:
session:
storage_id: session.storage.php_bridge
handler_id: session.handler.native_file
Note
If the legacy application requires its own session save handler, do not
override this. Instead set handler_id: ~
. Note that a save handler
cannot be changed once the session has been started. If the application
starts the session before Symfony is initialized, the save handler will
have already been set. In this case, you will need handler_id: ~
.
Only override the save handler if you are sure the legacy application
can use the Symfony save handler without side effects and that the session
has not been started before Symfony is initialized.
For more details, see Integrating with Legacy Sessions.