문제

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.

도움이 되었습니까?

해결책

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') . ']';

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top