Edit report at https://bugs.php.net/bug.php?id=71070&edit=1
ID: 71070
Updated by: laruence@php.net
Reported by: claytonsmith at outlook dot com
Summary: Custom session handler write method returns false,
warning message misleading
Status: Open
Type: Bug
Package: Session related
PHP Version: Irrelevant
-Assigned To:
+Assigned To: yohgaki
Block user comment: N
Private report: N
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[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