I already have memcached
installed in my servers and I've modified the default php.ini
to:
session.save_handler = memcached
session.save_path = "127.0.0.1:11211"
I'm using Amazon EC2 instances (Ubuntu 16.04 LTS) with Auto Scaling and Load Balancer, but I've a big question in my mind about the PHP memcached
. First, explaining my problem: I've stored sessions
in my Server A
and I've another Server B
also running. But, when I stop Server A
(that I'm connected with sessions
), the Load Balancer redirects me to Server B
and it looks like the sessions
are lost, because I'm disconnected of my website and he asks me to sign in again.
And I read this excerpt for use memcached for session storage on multiple servers (from here):
In your php.ini you should set session.save_path to the list of memcached servers, for example server1:11211, server2:11211.
But how can I say in who will be server1:11211
and server2:11211
being that I am using Auto Scaling and I may have "n" servers?
Your memcached server(s) should be outside of your ASG. As you know, state cannot be stored in ASG instances. So, either use AWS's Elasticache service or run your own memcached server, then point your ASG instances there.