|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-12-21 20:39 UTC] akauffman at ne4u dot com
Description:
------------
There seems to be a type casting problem with custom session handlers (specifically the memcached module) when session_regenerate_id() is called. Perhaps related to a null return value. It looks like it was introduced around 7RC3.
Error:
PHP message: PHP Catchable fatal error: session_regenerate_id(): Failed to create(read) session ID: user
Test script:
---------------
Problem:
<?php
set_ini('session.save_handler','memcached');
set_ini('session.save_path','host1:11211');
session_start();
$_SESSION['value'] = session_id();
session_regenerate_id();
?>
Work around:
<?php
set_ini('session.save_handler','memcached');
set_ini('session.save_path','host1:11211');
class MemcachedSession extends SessionHandler
{
public function read($session_id) {
return (string)parent::read($session_id);
}
}
$sess = new MemcachedSession();
session_set_save_handler($sess, true);
session_start();
$_SESSION['value'] = session_id();
session_regenerate_id();
?>
Expected result:
----------------
Shouldn't have to implement a workaround.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 13:00:01 2025 UTC |
In case its any easier for testing, this bug is affecting me too using the Cache Savehandler from ZF2. The workaround as suggested can also be applied there: <?php use Zend\Session\SaveHandler\Cache as ZendCache; class Cache extends ZendCache { public function read($id) { return (string) parent::read($id); } }Please note that - PHP 7.0 and up does not allow buggy return values from user save handler. user read handler MUST return "string" data for success always. - Native save handler must return SUCCESS for successful cases including non-existing session data. - FALSE/failure means "Something wrong in read" such as permission/network/etc errors. Checked memcached code and it needs this patch. @@ -326,6 +326,8 @@ PS_READ_FUNC(memcached) *val = zend_string_init(payload, payload_len, 1); free(payload); return SUCCESS; + } else if (status = MEMCACHED_NOTFOUND) { + *val = ZSTR_EMPTY_ALLOC(); } else { return FAILURE; } I made PR including new session features. https://github.com/php-memcached-dev/php-memcached/pull/164 Since this is not PHP session module bug, closed.