Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc7a44be

Browse files
digilistfabpot
authored andcommitted
Use proper error message when session write fails#20807
1 parentc6e1a49 commitc7a44be

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

‎src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespaceSymfony\Component\HttpFoundation\Session\Storage;
1313

14+
useSymfony\Component\Debug\Exception\ContextErrorException;
1415
useSymfony\Component\HttpFoundation\Session\SessionBagInterface;
1516
useSymfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler;
1617
useSymfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy;
@@ -208,7 +209,28 @@ public function regenerate($destroy = false, $lifetime = null)
208209
*/
209210
publicfunctionsave()
210211
{
211-
session_write_close();
212+
// Register custom error handler to catch a possible failure warning during session write
213+
set_error_handler(function ($errno,$errstr,$errfile,$errline,$errcontext) {
214+
thrownewContextErrorException($errstr,$errno,E_WARNING,$errfile,$errline,$errcontext);
215+
},E_WARNING);
216+
217+
try {
218+
session_write_close();
219+
restore_error_handler();
220+
}catch (ContextErrorException$e) {
221+
// The default PHP error message is not very helpful, as it does not give any information on the current save handler.
222+
// Therefore, we catch this error and trigger a warning with a better error message
223+
$handler =$this->getSaveHandler();
224+
if ($handlerinstanceof SessionHandlerProxy) {
225+
$handler =$handler->getHandler();
226+
}
227+
228+
restore_error_handler();
229+
trigger_error(sprintf(
230+
'session_write_close(): Failed to write session data with %s handler',
231+
get_class($handler)
232+
),E_USER_WARNING);
233+
}
212234

213235
$this->closed =true;
214236
$this->started =false;

‎src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/SessionHandlerProxy.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ public function __construct(\SessionHandlerInterface $handler)
3535
$this->saveHandlerName =$this->wrapper ?ini_get('session.save_handler') :'user';
3636
}
3737

38+
/**
39+
* @return \SessionHandlerInterface
40+
*/
41+
publicfunctiongetHandler()
42+
{
43+
return$this->handler;
44+
}
45+
3846
// \SessionHandlerInterface
3947

4048
/**

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp