Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

session_set_save_handler error in php7 #11733

Closed
bain2018 opened this issue May 3, 2016 · 5 comments
Closed

session_set_save_handler error in php7 #11733

bain2018 opened this issue May 3, 2016 · 5 comments
Labels
bug A bug report status: medium Medium

Comments

@bain2018
Copy link

bain2018 commented May 3, 2016

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 👍

/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;
}
@andresgutierrez andresgutierrez added the need script to reproduce Script is required to reproduce the issue label May 24, 2016
@GaiusValerius
Copy link

GaiusValerius commented May 28, 2016

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

@sergeyklay
Copy link
Contributor

Fixed in the 2.1.x branch

@sergeyklay sergeyklay added Bug - Medium and removed need script to reproduce Script is required to reproduce the issue labels May 28, 2016
@cq-z
Copy link
Contributor

cq-z commented Jun 1, 2016

@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 */

@sergeyklay sergeyklay reopened this Jun 1, 2016
@sergeyklay
Copy link
Contributor

I'll check

sergeyklay added a commit that referenced this issue Jun 3, 2016
@sergeyklay
Copy link
Contributor

Fixed in the 2.1.x branch

@niden niden added bug A bug report status: medium Medium and removed Bug - Medium labels Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: medium Medium
Projects
None yet
Development

No branches or pull requests

6 participants