Skip to content

Commit e31f75c

Browse files
committed
NEW Non-blocking filesystem session storage
1 parent c1bb4f6 commit e31f75c

File tree

7 files changed

+987
-1
lines changed

7 files changed

+987
-1
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
"symfony/config": "^7.0",
4848
"symfony/console": "^7.0",
4949
"symfony/dom-crawler": "^7.0",
50-
"symfony/filesystem": "^7.0",
50+
"symfony/filesystem": "^7.1",
51+
"symfony/finder": "^7.0",
5152
"symfony/http-foundation": "^7.0",
5253
"symfony/intl": "^7.0",
5354
"symfony/mailer": "^7.0",

src/Control/Session.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
namespace SilverStripe\Control;
44

55
use BadMethodCallException;
6+
use SilverStripe\Control\SessionHandler\FileSessionHandler;
67
use SilverStripe\Core\Config\Configurable;
8+
use SilverStripe\Core\Injector\Injector;
79

810
/**
911
* Handles all manipulation of the session.
@@ -119,6 +121,7 @@ class Session
119121
/**
120122
* @config
121123
* @var string
124+
* @deprecated 6.1.0 Use `session.save_path` in ini configuration instead.
122125
*/
123126
private static $session_store_path;
124127

@@ -139,6 +142,7 @@ class Session
139142
*
140143
* @see https://secure.php.net/manual/en/function.session-cache-limiter.php
141144
* @var string|null
145+
* @deprecated 6.1.0 Will be removed without equivalent functionality to replace it
142146
*/
143147
private static $sessionCacheLimiter = '';
144148

@@ -150,6 +154,12 @@ class Session
150154
*/
151155
private static $strict_user_agent_check = true;
152156

157+
/**
158+
* FQCN or injector service name for the session save handler.
159+
* If null, the save handler defined in `session.save_handler` ini configuration is used.
160+
*/
161+
private static ?string $save_handler = FileSessionHandler::class;
162+
153163
/**
154164
* Session data.
155165
* Will be null if session has not been started
@@ -299,6 +309,13 @@ public function start(HTTPRequest $request)
299309
session_save_path($session_path);
300310
}
301311

312+
// Set the session save handler if configured
313+
$saveHandlerServiceName = static::config()->get('save_handler');
314+
if ($saveHandlerServiceName !== null) {
315+
$saveHandler = Injector::inst()->get($saveHandlerServiceName);
316+
session_set_save_handler($saveHandler, true);
317+
}
318+
302319
session_start();
303320

304321
// Session start emits a cookie, but only if there's no existing session. If there is a session timeout

0 commit comments

Comments
 (0)