Reputation: 2664
We're using Amazon Web Services (AWS) and we have multiple web servers and a load balancer. The problem with the web servers is, that the $_SESSION is unique for each one. I'm keeping some information about the user in the $_SESSION.
What is the proper way to synchronize this information? Is there any way to unite the place, where those sessions are being kept, or should I use MySQL to store this data (I don't really like the last option)?
Upvotes: 3
Views: 6313
Reputation: 444
I think what you are looking for is 'Sticky Sessions'. If I'm right about that, Amazon gives you two different options.
Load Balancer(duration-based, I recommend this one) http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/US_StickySessions.html#US_EnableStickySessionsLBCookies
And application based session stickiness http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/US_StickySessions.html#US_EnableStickySessionsAppCookies
Upvotes: 7
Reputation: 1084
To add to the above answer, what your looking for a distributed cache like DynamoDB which is a paid amazon service. Its amazingly fast and brilliant to use but if you are look for some other open source alternatives you can look at the following memory read/write options.
Upvotes: 1
Reputation: 64751
While conceptually similar to the MySQL option you are trying to avoid for some reason, a pretty appealing option for usage within Amazon Web Services (AWS) is the recently introduced Scalable Session Handling in PHP Using Amazon DynamoDB, which addresses that Typical session handling in PHP is not scalable, thus requiring some kind of custom solution anyway:
Sessions are used to preserve short-term data across multiple HTTP requests [...]. PHP’s native session handler stores session data to the local file system; however, this approach becomes unreliable in distributed web applications. On subsequent requests the user may not be routed to the same server causing the data to be effectively forgotten. The user will be logged out and confused.
To overcome this issue, PHP developers have implemented custom solutions for storing their users’ session data using databases, shared file systems, Memcache servers, tamper-proof cookies, and other storage mechanisms. [...] [emphasis mine]
Depending on your use case you might want to give this potentially very fast session store a try accordingly.
Upvotes: 4