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 3 commits
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
30 changes: 30 additions & 0 deletions components/http_foundation/session_configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ easily serve as examples if you wish to write your own.

* :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\PdoSessionHandler`
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\MemcachedSessionHandler`
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\MigratingSessionHandler`
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\RedisSessionHandler`
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\MongoDbSessionHandler`
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\NullSessionHandler`
Expand All @@ -87,6 +88,35 @@ Example usage::
$sessionStorage = new NativeSessionStorage(array(), new PdoSessionHandler($pdo));
$session = new Session($sessionStorage);

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.

It can be used to support the following 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.

Example usage::

use Symfony\Component\HttpFoundation\Session\Storage\Handler\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);

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

// Final step - switching to the new storage handler!
$sessionStorage = $newSessionStorage;

Configuring PHP Sessions
~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down