Recently I just started using AWS ElastiCache for a Laravel application. The application is running on 2 instances behind a ELB and handles about 6-10 request/second. Everything was going fine when I launched the application but then I started to receiving connection errors to the application with high latency and timeouts. The error messages was as follows:
[2016-05-17 07:28:25] production.ERROR: exception 'RuntimeException' with message 'Could not establish Memcached connection.' in /srv/ensemble/laravel/vendor/laravel/framework/src/Illuminate/Cache/MemcachedConnector.php:38 Stack trace:
#0/srv/ensemble/laravel/vendor/laravel/framework/src/Illuminate/Cache/CacheManager.php(164): Illuminate\Cache\MemcachedConnector->connect(Array)
#1 /srv/ensemble/laravel/vendor/laravel/framework/src/Illuminate/Cache/CacheManager.php(102): Illuminate\Cache\CacheManager->createMemcachedDriver(Array) #2 /srv/ensemble/laravel/vendor/laravel/framework/src/Illuminate/Cache/CacheManager.php(77): Illuminate\Cache\CacheManager->resolve('memcached')...
For my setup I'am using:
To solve my issue for the time being I have installed memcached on a separate EC2 instance and have had no issues.
My question is, do I need to use AWS ElastiCache PHP Client instead of the php5-memcached to use Elasticache? I was under the impression that Elasticache was a drop in replacement for Memcached and could be used with out a problem.
Thank you for the help!
There are few important consideration when using manage services in AWS such as Elasticache.
Regarding your issue, the application cannot established connection to the cache instance, this error shows that the problem occurs somewhere in the network. This issue is very common.
And most likely caused by
The EC2 instance doesn't have routes that can be used to access the elasticache endpoint. This issue occurs if you provisioned the Elasticache from a different VPC (different from VPC used by your application EC2). To solve this you either move the cache to the same VPC where the EC2 reside or You need to Peer the 2 VPC and create local route to establish connection.
The EC2 instance has the valid route or they are in the same VPC however it's blocked by Elasticache SecurityGroup(SG). To solve this you need to check whether your EC2 Private IP is listed to Elasticache SG inbound rules with the memcache port. allow IP 172.0.1.1/32 to port 11211
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With