Cphalcon: session_set_save_handler error in php7

Created on 3 May 2016  Â·  5Comments  Â·  Source: phalcon/cphalcon

when use memcache,redis to save session, but session_set_save_handler->write has a bug,
function write($id, $data) need bool return, but in the source miss the return :+1:

/phalcon/session/adapter/redis.zep line:125

public function write(string sessionId, string data)
{
    // this coding don't have the value return
    this->_redis->save(sessionId, data, this->_lifetime); 
}

so ,i think the follow coding maybe right:

public function write(string sessionId, string data)
{
    this->_redis->save(sessionId, data, this->_lifetime);
    // just return true cause of the redis cache save
    // method don't have the status of save return
    return true;
}
bug medium

Most helpful comment

Fixed in the 2.1.x branch

All 5 comments

I can reproduce this bug, if i create a class that extends \Phalcon\Session\Adapter\Redis and overwrite method write:

/**
 * @param string $sessionId
 * @param string $data
 * @return bool
 */
public function write($sessionId, $data)
{
    parent::write($sessionId, $data);

    return true;
}

everything works fine.

To reproduce:
I use this to initialize the session with redis-adapter:

use Phalcon\Session\Adapter;
use Phalcon\Session\Adapter\Redis;

$session = function () use ($configuration): Adapter {
    $session = new Redis([
        'uniqueId'   => 'some-uniqueID',
        'lifetime'   => 2592000,
        'prefix'     => 'my-prefix-',
        'host'       => $configuration->host,
        'port'       => $configuration->port,
        'auth'       => $configuration->password,
        'persistent' => true,
    ]);

    $session->start();

    return $session;
};

// Do some other, irrelevant stuff

$this->di->set('session', $session);

Then you can see at the bottom of the page:

Warning: session_write_close(): Session callback expects true/false return value in Unknown on line 0
Warning: session_write_close(): Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/var/lib/php/sessions) in Unknown on line 0

Hope this helps.

Phalcon-Version: 2.0.11
PHP: 7.0.4-7ubuntu2.1

Fixed in the 2.1.x branch

@sergeyklay
PHP Warning: session_destroy(): Session callback expects true/false return value
redis->delete($id) renturn not bool

Documentation :

Return value

Long Number of keys deleted.

$redis->delete('key1', 'key2'); /* return 2 */
$redis->delete(array('key3', 'key4')); /* return 2 */

I'll check

Fixed in the 2.1.x branch

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dimak08 picture dimak08  Â·  3Comments

bestirani2 picture bestirani2  Â·  3Comments

EquaI1ty picture EquaI1ty  Â·  3Comments

TimurFlush picture TimurFlush  Â·  3Comments

borisdelev picture borisdelev  Â·  3Comments