We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Redis Sesion adapter using file to store session

Hello everyone for some reason, the redis adapter is using a file to store the session instead of redis itself

this is my config

$di->set('session', function () {

  $session = new SessionAdapter();
  $session->setOptions(array(
      "host" => "localhost",
      "port" => 6379,
      "persistent" => true,
      "lifetime" => 3600,
      "prefix" => "SES_",
      "index" => 0
  ));
  $session->start();
  return $session;
});

and when I check " /var/lib/php/sessions " (where file sessions are stored), a file is created whenever I save data into the session object, and when I delete the files the session data is lost, if im not mistaken this is the behaviour of the file adapter because when i use " redis_cli keys * " it retuns an empty set and it behaves weird because I can only access the session stored objects on certain controllers whereas in others it returns null, when i use var_dump($this->session) i get all the options i have set, when using th file adapter everything works fine, any help would be appreciated

P.D. also i get this warning, thou it may not be just a warning " Warning: session_set_save_handler(): Cannot change save handler when session is active in ... on line xxx " but only in the controllers where i can access the session

P.D.2 when using redis as backend cache it works fine too, session is the only problem

Phalcon version 3.3.1

php version 7.2.3

There are different session adapters in Phalcon, just clarifying you are using the Redis one?


$di->setShared('session',function(){
  $session = new \Phalcon\Session\Adapter\Redis(array(
   'uniqueId' => 'my-private-app',
    'host' => 'localhost',
    'port' => 6379,
    'auth' => 'foobared',
   'persistent' => false,
   'lifetime' => 3600,
   'prefix' => 'my_'
));
return $session;
});

There are different session adapters in Phalcon, just clarifying you are using the Redis one?


$di->setShared('session',function(){
 $session = new \Phalcon\Session\Adapter\Redis(array(
  'uniqueId' => 'my-private-app',
   'host' => 'localhost',
   'port' => 6379,
   'auth' => 'foobared',
  'persistent' => false,
  'lifetime' => 3600,
  'prefix' => 'my_'
));
return $session;
});

Im doing this

use Phalcon\Session\Adapter\Redis as SessionAdapter;



85.5k

make sure redis is working, 2 options, bad config or redis is not accepting your connection

I am using this extension, which i have never seen a problem with https://github.com/phpredis/phpredis . It allows session to be stored in redis + a redis class to use set,get etc...

edited Jun '18

make sure redis is working, 2 options, bad config or redis is not accepting your connection

I am using this extension, which i have never seen a problem with https://github.com/phpredis/phpredis . It allows session to be stored in redis + a redis class to use set,get etc...

it is working with this config as backend cache

use Phalcon\Cache\Backend\Redis as BackendCache;
use Phalcon\Cache\Frontend\Data;

$di->set('cache', function () {
    $cache = new BackendCache(new Data(['lifetime' => 604800]),
        [
            "host"       => "localhost",
            "port"       => 6379,
            "persistent" => true,
            "index"      => 0,
            "statsKey"   =>'_PHCR'
        ]);

    return $cache;
});

so i dont think my redis server is the problem but the adapter, idk if i'm the only one having this issue, if yours is working fine with the phalcon adapter then I guess that's the case