|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-12-09 06:53 UTC] claytonsmith at outlook dot com
Description: ------------ When using a custom session handler it will generate a misleading error message about why the write failed to happen. It says to verify the session.save_path is correct but because we are using a custom session handler, it may never be attempting to write to that directory. Example of one user running into this problem: http://stackoverflow.com/questions/34117651/php7-symfony-2-8-failed-to-write-session-data/ It would be better to have a more clear warning message to diagnose why this occurs. Test script: --------------- <? error_reporting(E_ALL); ini_set('display_errors', 1); class TestHandler extends SessionHandler { public function write($id, $data) { // Write somewhere that is not a file return false; } } $saveHandler = new TestHandler(); session_set_save_handler( array(&$saveHandler, 'open'), array(&$saveHandler, 'close'), array(&$saveHandler, 'read'), array(&$saveHandler, 'write'), array(&$saveHandler, 'destroy'), array(&$saveHandler, 'gc') ); session_start(); $_SESSION['value'] = 123; var_dump($_SESSION); Expected result: ---------------- PHP Warning: Unknown: Failed to write session data using custom session handler in custom-session-handler.php on line 123 Actual result: -------------- Warning: session_write_close(): Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/tmp) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 23:00:01 2025 UTC |
We can not get the file/line info, instead we can only warn about write failed, however I am not what message is better: diff --git a/ext/session/session.c b/ext/session/session.c index 5e4831c..6981b8f 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -572,11 +572,15 @@ static void php_session_save_current_state(int write) /* {{{ */ } if ((ret == FAILURE) && !EG(exception)) { - php_error_docref(NULL, E_WARNING, "Failed to write session data (%s). Please " - "verify that the current setting of session.save_path " - "is correct (%s)", - PS(mod)->s_name, - PS(save_path)); + if (!PS(mod_user_implemented)) { + php_error_docref(NULL, E_WARNING, "Failed to write session data (%s). Please " + "verify that the current setting of session.save_path " + "is correct (%s)", + PS(mod)->s_name, + PS(save_path)); + } else { + php_error_docref(NULL, E_WARNING, "Failed to write session data (%s)", PS(mod)->s_name); + } } } } thanks