Skip to content

Commit 91aa58d

Browse files
committed
Adding MigratingSessionHandler docs
1 parent e6100db commit 91aa58d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

components/http_foundation/session_configuration.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ easily serve as examples if you wish to write your own.
7373

7474
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\PdoSessionHandler`
7575
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\MemcachedSessionHandler`
76+
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\MigratingSessionHandler`
7677
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\RedisSessionHandler`
7778
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\MongoDbSessionHandler`
7879
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\NullSessionHandler`
@@ -87,6 +88,35 @@ Example usage::
8788
$sessionStorage = new NativeSessionStorage(array(), new PdoSessionHandler($pdo));
8889
$session = new Session($sessionStorage);
8990

91+
Migrating Between Save Handlers
92+
-------------------------------
93+
94+
The :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\MigratingSessionHandler`
95+
can be used to migrate between old and new save handlers without losing session data.
96+
97+
It can be used to support the following workflow:
98+
99+
* 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.
100+
* After your session gc period, verify the data in the new handler
101+
* 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.
102+
* After verifying everything, switch from the migrating handler to the new handler
103+
104+
Example usage::
105+
106+
use Symfony\Component\HttpFoundation\Session\Storage\Handler\MigratingSessionHandler;
107+
108+
$oldSessionStorage = ...;
109+
$newSessionStorage = ...;
110+
111+
// First step, for the the garbage collection period so we get all sessions in the new storage handler
112+
$sessionStorage = new MigratingSessionHandler($oldSessionStorage, $newSessionStorage);
113+
114+
// Second step, just while we verify that the new session storage handler works as expected
115+
$sessionStorage = new MigratingSessionHandler($newSessionStorage, $oldSessionStorage);
116+
117+
// Final step - switching to the new storage handler!
118+
$sessionStorage = $newSessionStorage;
119+
90120
Configuring PHP Sessions
91121
~~~~~~~~~~~~~~~~~~~~~~~~
92122

0 commit comments

Comments
 (0)