8000 Adding MigratingSessionHandler docs by rossmotley · Pull Request #9496 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

Adding MigratingSessionHandler docs #9496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 24, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Reworded and simplified
  • Loading branch information
javiereguiluz authored May 22, 2018
commit 386f6393e005f3b7db92c9e17281a2faeb427348
31 changes: 13 additions & 18 deletions components/http_foundation/session_configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,30 +91,25 @@ Example usage::
Migrating Between Save Handlers
-------------------------------

The :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\MigratingSessionHandler`
can be used to migrate between old and new save handlers without losing session data.
If your application changes the way sessions are stored, use the
:class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\MigratingSessionHandler`
to migrate between old and new save handlers without losing session data.

It can be used to support the following workflow:
This is the recommended migration workflow:

* Switch to the migrating handler, with your new handler as the write-only one. The old handler behaves as usual and sessions get written to the new one.
* After your session gc period, verify the data in the new handler
* Update the migrating handler to use the old handler as the write-only one, so the sessions will now be read from the new handler. This step allows easier rollbacks.
* After verifying that the sessions in your app are working, switch from the migrating handler to the new handler.
#. Switch to the migrating handler, with your new handler as the write-only one.
The old handler behaves as usual and sessions get written to the new one::

Example usage::

use Symfony\Component\HttpFoundation\Session\Storage\Handler\MigratingSessionHandler;

$oldSessionStorage = ...;
$newSessionStorage = ...;
$sessionStorage = new MigratingSessionHandler($oldSessionStorage, $newSessionStorage);

// First step, for the the garbage collection period so we get all sessions in the new storage handler
$sessionStorage = new MigratingSessionHandler($oldSessionStorage, $newSessionStorage);
#. After your session gc period, verify that the data in the new handler is correct.
#. Update the migrating handler to use the old handler as the write-only one, so
the sessions will now be read from the new handler. This step allows easier rollbacks::

// Second step, just while we verify that the new session storage handler works as expected
$sessionStorage = new MigratingSessionHandler($newSessionStorage, $oldSessionStorage);
$sessionStorage = new MigratingSessionHandler($newSessionStorage, $oldSessionStorage);

// Final step - switching to the new storage handler!
#. After verifying that the sessions in your application are working, switch
from the migrating handler to the new handler.
$sessionStorage = $newSessionStorage;

Configuring PHP Sessions
Expand Down
0