diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php index 274b0df6b9e39..6f1f9bef32ede 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php @@ -11,6 +11,7 @@ namespace Symfony\Component\HttpFoundation\Session\Storage; +use Symfony\Component\Debug\Exception\ContextErrorException; use Symfony\Component\HttpFoundation\Session\SessionBagInterface; use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler; use Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy; @@ -223,7 +224,28 @@ public function regenerate($destroy = false, $lifetime = null) */ public function save() { - session_write_close(); + // Register custom error handler to catch a possible failure warning during session write + set_error_handler(function ($errno, $errstr, $errfile, $errline, $errcontext) { + throw new ContextErrorException($errstr, $errno, E_WARNING, $errfile, $errline, $errcontext); + }, E_WARNING); + + try { + session_write_close(); + restore_error_handler(); + } catch (ContextErrorException $e) { + // The default PHP error message is not very helpful, as it does not give any information on the current save handler. + // Therefore, we catch this error and trigger a warning with a better error message + $handler = $this->getSaveHandler(); + if ($handler instanceof SessionHandlerProxy) { + $handler = $handler->getHandler(); + } + + restore_error_handler(); + trigger_error(sprintf( + 'session_write_close(): Failed to write session data with %s handler', + get_class($handler) + ), E_USER_WARNING); + } if (!$this->saveHandler->isWrapper() && !$this->saveHandler->isSessionHandlerInterface()) { // This condition matches only PHP 5.3 with internal save handlers diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/SessionHandlerProxy.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/SessionHandlerProxy.php index 81643c74b4001..592cfe166f8c7 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/SessionHandlerProxy.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/SessionHandlerProxy.php @@ -35,6 +35,14 @@ public function __construct(\SessionHandlerInterface $handler) $this->saveHandlerName = $this->wrapper ? ini_get('session.save_handler') : 'user'; } + /** + * @return \SessionHandlerInterface + */ + public function getHandler() + { + return $this->handler; + } + // \SessionHandlerInterface /**