Search code examples
phpsessionauthenticationcluster-computingcloud-hosting

Setup Php Session Login On Clustered Servers


I have 3 servers. One MySQL database and 2 Apache web servers with a load balancer. Www1 copies it's data to www2 every other minute and vice versa. The issue I'm having is that say a user goes to the site and hits the www1 server, attempts to login, the page refreshes and now they are on www2 and then not logged in. Then if you refresh the page and if you hit www1 you are logged on again. This happens for about 2 minutes until the servers match info and depending which one does first you might not be logged in anymore. I set up a simple php session login. Does anyone have experience with working on clustered systems and setting up logins. Any advice would help. Hank you for your time.


Solution

  • Since you already have a MySQL Database. Create database based PHP sessions. The session information can be passed via the url and auto clean after so many minutes of inactivity and the page is loaded requiring customer to relogin.