Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Redis Session not destroyed

Hi all,

I'm have some troubles with redis session when I'm trying to destroy it.

Configuration (Virtualbox with 4 VM) :

HTTP Server

  • nginx v1.10.2
  • PHP Version 7.0.13-1~dotdeb+8.1
  • Phalcon 3.0.2

Cache Server

  • Redis v3.2.5

Session Server

  • Redis v3.2.5

Databases Server

  • MariaDB
  • MongoDB

Bootstrap cache setting :

        $cacheConfig = new Config( require ($this->servicesDir . 'cache.php'));

        $this->di->set('cache', function () use ($cacheConfig) {
            $frontCache = new \Phalcon\Cache\Frontend\Data(
                [
                    'lifetime' => $cacheConfig->lifetime
                ]
            );

            $cache = new \Phalcon\Cache\Backend\Redis($frontCache, $cacheConfig->redis->toArray());

            return $cache;
        });

Redis cache server works perfectly with cache settings (maxmemory ans momemry-policy) and AUTH.

Then i'm using session with another redis server (normal settings), I try using session but it's seems when i'm using destroy function, it doesn't work...

Bootstrap session setting :

        $cacheConfig = new Config( require ($this->servicesDir . 'session.php'));
        $this->di->set('session', function () use ($cacheConfig) {
            $session = new \Phalcon\Session\Adapter\Redis($cacheConfig->toArray());
            $session->start();
            return $session;
        });

Test used :

        $this->session->set('foo', 'Bar');
        echo $this->session->get('foo');  // OK

        $this->session->set('product', ['name' => 'ipad', 'price' => '299.90€']); 
        var_dump($this->session->get('product'));  // OK

        $this->session->destroy();

        echo $this->session->get('foo');  // data not destroyed
        var_dump($this->session->get('product'));  // data not destroyed

Data not deleted on remote server.

Any Idea why session destroy not work ?

Thx.



35.5k
Accepted
answer

This may be the same case as an older question:

Destroy the session does not remove data from the $_SESSION superglobal

https://forum.phalconphp.com/discussion/7713/session-not-destroy-with-redis



3.2k

It means "destroy" method is useless if we hate to use PHP super-global $_SESSION.

I hape there is a solution instead using :

    session_unset();
    session_regenerate_id(true);

I hope there is a solution for making clean code.

Thx for reply.