Bug #73616 [Opn->Nab]: session file read warning when using custom DB session handler

From: Date: Mon, 28 Nov 2016 00:14:12 +0000
Subject: Bug #73616 [Opn->Nab]: session file read warning when using custom DB session handler
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-205666@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73616&edit=1 ID: 73616 Updated by: yohgaki@php.net Reported by: jfoster at cervistech dot com Summary: session file read warning when using custom DB session handler -Status: Open +Status: Not a bug Type: Bug Package: Session related PHP Version: 7.1.0RC6 Block user comment: N Private report: N New Comment: 2 problems in your example code. 1) You should not register save handler as this code. Create handler object, then register it by sesion_set_save_handler() outside of the object. 2) You should return "string" data from read(). Do you return "string"? It seems this is the reason why you get error from read() For 1), you may register save handler methods like this, but intended usage is to register "object", not "methods". Refer this test script for correct usage. http://lxr.php.net/xref/PHP-7.0/ext/session/tests/session_set_save_handler_class_001.phpt If you still have problem with modified save handler object, reopen this bug and paste whole save handler code. Previous Comments: ------------------------------------------------------------------------ [2016-11-27 23:05:11] jfoster at cervistech dot com Description: ------------ When using session_set_save_handler to implement a custom database based session handler, PHP is throwing the following warning on session_start(): PHP Warning: session_start(): Failed to read session data: user (path: C:\PHP\session\) The session handler is functioning correctly and reading/writing correctly to the DB, but is throwing the warning when no files are being used for sessions. This same code has functioned without throwing the warning for every version of PHP since PHP 5.4. The warning only started occurring in 7.1 Test script: --------------- $sess = new SessionManager(); session_start(); class SessionManager { var $life_time; #function SessionManager() function __construct() { // Read the maxlifetime setting from PHP $this->life_time = get_cfg_var("session.gc_maxlifetime"); // Register this object as the session handler session_set_save_handler( array($this, "_open"), array($this, "_close"), array($this, "_read"), array($this, "_write"), array($this, "_destroy"), array($this, "_gc") ); } function _open() { return true; } function _close() { return true; } function _read($id) { //code to read session data from db based on $id } function _write($id, $data) { //code to write/update session data to db based on $id return TRUE; } function _destroy($id) { //code to delete session data from db based on $id return TRUE; } function _gc() { //code to delete session data from db based on timestamp return true; } } Expected result: ---------------- Session handler to process session without throwing read file warning Actual result: -------------- Session handler processes session data from db successfully, but throws file read error. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=73616&edit=1

« previous php.bugs (#205666) next »