Reputation: 457
I am using an elasticache cluster on aws. The details are
Engine: Memcached
Cache Engine Version: 1.4.5
On doing telnet to the node , with node ip-port the memcached server is accessible always. But when trying to connect with PHP , sometimes the memcache object is not getting created at all.
The client uses php-pecl-memcache-3.0.5 for connection.
The code being used is as
$cache = memcache_connect(MEMCACHE_HOST, MEMCACHE_PORT);
What happens is at times, the $cache object is not getting created.
Please guide how could i solve the issue. Thanks.
Upvotes: 2
Views: 2473
Reputation: 982
Try this:
<?php
$server_endpoint = "xxx.xx.xfg.sae1.cache.amazonaws.com";
$server_port = 11211;
if (version_compare(PHP_VERSION, '5.4.0') < 0) {
//PHP 5.3 with php-pecl-memcache
$client = new Memcache;
$client->connect($server_endpoint, $server_port);
//If you need debug see $client->getExtendedStats();
$client->set('myKey', 'My Value PHP 5.3');
} else {
//PHP 5.4 with php54-pecl-memcached:
$client = new Memcached;
$client->addServer($server_endpoint, $server_port);
$client->set('myKey', 'My Value PHP 5.4');
}
echo 'Data in the cluster: [' . $client->get('myKey') . ']';
Upvotes: 2
Reputation: 2488
Now uses updated versions of memcached (currently 1.4.14) and I believe that the connection problems could have been the result of bugs in the 1.4.5 version of memcache.
Upvotes: 1