How to save a session over load balancing?

The project I'm working on is based on several servers that use a load balancer. The problem is that I cannot maintain a PHP session across all servers. What is the best way to manage a load balancing session ...?

+7
php webserver
source share
3 answers

I can think of these two methods for this purpose.

  • Use a clustered web application server where the session is accessible to all servers.
  • Use IP layer information to maintain proximity between the user and the server.
+9
source share

Using SSL and the Load Balancer, distribute SSL on the load balancer, but not on the servers on the rear panel. Thus, you only need one certificate on one server. The load balancer then talks to the back-end servers using simple 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 check the request for jsessionid.

+6
source share

Copy the method of storing the session inside the database that supports all of your many servers. Servers always get the same _PHPSESSID because it is written as a domain cookie.

So, if you know the session identifier - you know what you need to query from the database serving the sessions.

0
source share

All Articles