AWS Elastic Beanstalk and PHP sessions

前端 未结 3 2034
再見小時候
再見小時候 2020-12-31 19:30

I currently have a php application in development on an AWS EC2 instance but I\'ve decided to move it to Elastic Beanstalk to take advantage of the autoscaling functionality

3条回答
  •  孤城傲影
    2020-12-31 20:12

    Moving your application to Elastic Beanstalk means that from now on your application will possibly run on multiple physical web server instances. (That's what you're paying for.) This means that a request with a valid session ID could be forwarded to a server which does not possess that session file on disk (you seem to be using the file-based session handler as shown in the question).

    Solution A (preferred)
    You need to store sessions in a shared location where they can be accessed by all of your web server instances. Amazon typically recommends DynamoDB for this, but it could also be MySQL or Redis or even the Elastic Cache provided by AWS.

    Solution B (slower, unreliable, needs SSL termination at load balancer)
    Configure your load balancer in a way that it uses "sticky" sessions. This means that the L.B. will unwrap HTTP(S) packets, look for the session cookie and then forward the request to the correct web server where the session lives.

提交回复
热议问题