Bug #71070 [Com]: Custom session handler write method returns false, warning message misleading
| From: | claytonsmith at outlook dot com | Date: | Wed, 09 Dec 2015 22:46:14 +0000 |
| Subject: | Bug #71070 [Com]: Custom session handler write method returns false, warning message misleading | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-197753@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
Comment by: claytonsmith at outlook dot com
Reported by: claytonsmith at outlook dot com
Summary: Custom session handler write method returns false,
warning message misleading
Status: Assigned
Type: Bug
Package: Session related
PHP Version: Irrelevant
Assigned To: yohgaki
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[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