Bug #71070 [Asn->Csd]: Custom session handler write method returns false, warning message misleading

From: Date: Mon, 18 Jan 2016 03:05:39 +0000
Subject: Bug #71070 [Asn->Csd]: Custom session handler write method returns false, warning message misleading
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-198744@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71070&edit=1 ID: 71070 Updated by: yohgaki@php.net Reported by: claytonsmith at outlook dot com Summary: Custom session handler write method returns false, warning message misleading -Status: Assigned +Status: Closed Type: Bug Package: Session related PHP Version: Irrelevant Assigned To: yohgaki Block user comment: N Private report: N New Comment: Automatic comment on behalf of yohgaki Revision: http://git.php.net/?p=php-src.git;a=commit;h=05e87fa41855c58de6435eb1c80a1bc6454362f7 Log: Fixed bug #71070 Custom session handler write method returns false, warning message misleading This is commited to master only. If you have better error message suggestion, feel free to improve it. Previous Comments: ------------------------------------------------------------------------ [2015-12-09 23:15:10] claytonsmith at outlook dot com If it using a custom session handler it could say: "An error occurred when writing session data (%s)" Laurence: If the error message is ""Failed to write session data (%s)" it will still be confusing because if you google that error people will find every reference to the 'old' error message that contains the same string. ------------------------------------------------------------------------ [2015-12-09 22:46:13] claytonsmith at outlook dot com Is there not a way to know that it is using a custom session handler? If the default write behavior is overridden it can show an error at least mentioning that the session write failed due to an error in the custom session handler. If it's not using a custom session handler, or if it is known that the default session write handler is called, it would then produce one of your suggested error messages. Mentioning session.save_path in the error message on a custom session handler has nothing to do with the overridden behavior. ------------------------------------------------------------------------ [2015-12-09 21:44:03] yohgaki@php.net @laruence We get this kind of report that complaining file/line info is not displayed on save handler error on occasions, but we cannot get file/line info at the code. The most common error is save path permission (wrong or non existent dir) and file permissions (user uses multiple account for session data) How about Warning: session_write_close(): Failed to write session data (user). Verify session.save_path(/tmp) current setting and account has correct permission. Access to session data by multiple user accounts may cause this error because of file access permission also. File and line number is not displayed due to implementation limitation. This is rather long, but user may understand what is going on at least. Any suggestions are appreciated. ------------------------------------------------------------------------ [2015-12-09 15:02:38] laruence@php.net 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 ------------------------------------------------------------------------ [2015-12-09 06:53:23] 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) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71070&edit=1

« previous php.bugs (#198744) next »