Home » Php » php – How To maintain Session over Load Balancer?

php – How To maintain Session over Load Balancer?

Posted by: admin July 12, 2020 Leave a comment

Questions:

The Project i am working on is based on multiple server which uses load balancer. The Problem is i can not maintain PHP session through out all servers.What is the best way to manage session over Load Balancer … ?

How to&Answers:

i can think of these two methods for this purpose.

  1. Use a clustered web application server where the session are available for all the servers
  2. Use IP level information to maintain affinity between a user and a server

Answer:

Working SSL & Load Balancer, it is common to put the SSL on the load balancing server, but not on the back end servers. So you only need one certificate on one server. The load balancer then talks to the back end servers using plain HTTP. This obviously requires that your back end servers are not directly accessible from the internet.This load balancer is responsible for decrypting the request, it will also be able to inspect the request for a jsessionid.

Answer:

Dig the way to store session inside DB that maintains all of your multiple servers.
Servers always get the same _PHPSESSID because of it’s written as domain’s cookie.

So if you know session ID — you know what to query from DB that serves sessions.