I'm using Nicolasff Redis-PHP extension(https://github.com/nicolasff/phpredis) for handling sessions on multipe servers. So I have changed my session handlers as suggested:

session.save_handler = redis
session.save_path = "tcp://host1:6379?weight=1"

On logout, I am destroying the session like so on one server:

setcookie('session_id', NULL, time() - 4800);
session_unset();
session_destroy();
session_write_close();
setcookie(session_name(),'',0,'/');
session_regenerate_id(true);
session_destroy();

But the problem is the session is only destroyed one servers and not the other. How can I ensure that session is destroyed on all servers?

share|improve this question
    
Probable solution will be to store session in single RedisStore instance. So that destroying session on one server will destroy on others too. – bsnrijal Nov 14 '13 at 20:03

Note the description of the parameter "weight" in phpredis:

the weight of a host is used in comparison with the others in order to customize the session distribution on several hosts. If host A has twice the weight of host B, it will get twice the amount of sessions. In the example, host1 stores 20% of all the sessions (1/(1+2+2)) while host2 and host3 each store 40% (2/1+2+2). The target host is determined once and for all at the start of the session, and doesn't change. The default weight is 1.

It`s means that phpredis choose destination server by session id and make this choose each time your change it. In your code:

  //Both of next lines delete session key in redis stotage.
  //Read from 411 line of redis_session.c 
  session_unset();
  session_destroy();

  //delete current session (due to $delete_old_session = true) and start new 
  //session i.e. select new server and write data.
  session_regenerate_id(true); 

In other words - you do not need to do anything special if you are using N servers to store session in radis with phpredis. Simply remove the session with session_unset or session_destroy if you do not need it, or call session_regenerate_id if need new session id for already started session.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.