php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73835 Redis session handler bug
Submitted: 2016-12-29 17:25 UTC Modified: 2016-12-29 17:34 UTC
From: ben at ajmadison dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.1.0 OS: Centos 7.3
Private report: No CVE-ID: None
 [2016-12-29 17:25 UTC] ben at ajmadison dot com
Description:
------------
There is a problem in the redis 3.1 extension in php 7+, when redis is used as a session handler. The problem only manifests itself when new session is being created, and has to do with php7 expecting a String. Please reference a related bug: https://bugs.php.net/bug.php?id=71187 which is for Memcached but Redis seems to have the same issue.

The following php workaround fixed the problem:

class RedisSession extends SessionHandler
{
        public function read($session_id) {
                return (string)parent::read($session_id);
        }
}

$sess = new RedisSession();
session_set_save_handler($sess, true);

Test script:
---------------
in php.ini i have:

session.save_handler = redis
session.save_path = "tcp://localhost:6379?weight=1"

in test.php i have:

session_start();

Expected result:
----------------
I would expect new session to be initialized.


Actual result:
--------------
Warning: session_start(): Failed to read session data: redis (path: tcp://local

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-29 17:34 UTC] aharvey@php.net
-Status: Open +Status: Not a bug
 [2016-12-29 17:34 UTC] aharvey@php.net
This appears to be fixed in https://github.com/phpredis/phpredis/issues/1062. Closing, as this isn't a PHP bug, and phpredis tracks issues on GitHub instead of here.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC