PHP sessions on auto-scale servers

I am working on a PHP web application deployed to Amazon Web Services. We have load balancers in front of automatic scalable application servers.

The problem we are currently facing is processing sessions. Although sticky sessions would be a wise decision, we would like to continue the sessions for quite some time (weeks ideally). This can affect load balancing performance over time. In addition, the use of automatic scaling will mean that from time to time we delete the server and thereby lose all active sessions on it. Of course, we could just use a common database for storing sessions, but I'm a little worried about performance if each query requires a different reverse database connection.

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

Thanks in advance for your help, Ross

+3
source share
1 answer

I would use a special session solution in which sessions are stored in a database.

This way, all web servers will have access to the same session repository, and you can decide how long the session should be kept.

You can create something that works with regular PHP sessions or a fully autonomous class to handle them.

I did something similar to share the session between asp and asp.net on different services, and it works.

If performance is a problem, use a separate database, memcached or mysql cluster (also memory), or possibly mongoDB for sessions.

+2
source

Source: https://habr.com/ru/post/1794097/


All Articles