Ross McFarlane
Ross McFarlane

Reputation: 4254

PHP Sessions on Auto-Scaling Servers

I'm working on a PHP web app deployed to Amazon Web Services. We have load balancers in front of auto-scaled application servers.

The problem we're facing at the moment is handling sessions. While sticky sessions would be a reasonable solution, we'd like to persist sessions for quite a long time (weeks ideally). This is likely to impair the performance of the load balancer over time. Also, using auto-scaling will mean that, from time to time, we'll remove a server and thus lose all of the active sessions on it. Of course, we could just use a common database to store sessions, but I'm a bit concerned about performance if every request requires another round-trip to the DB.

I'd be grateful if you could suggest any solutions that have worked for you, or any ideas that we could try.

Thanks in advance for your help, Ross

Upvotes: 4

Views: 1753

Answers (1)

David Mårtensson
David Mårtensson

Reputation: 7620

I would use a custom session solution where the sessions are stored in the datatabase.

That way all webservers will have access to the same session store and also you can decide for your self how long a session should be kept.

You could either build something that works with PHP normal sessions or a completely stand alone class to handle them.

I did something similar to share a session between asp and asp.net over different serves and it works.

If performance is an issue, use a separate database, memcached or mysql cluster (also memory stored) or maybe a mongoDB for the sessions.

Upvotes: 2

Related Questions