我正在 aws 上使用 elasticache 集群。详情如下
Engine: Memcached
Cache Engine Version: 1.4.5
在对节点进行 telnet 时,使用节点 ip-port 始终可以访问 memcached 服务器。 但是当尝试连接 PHP 时,有时 memcache 对象根本没有被创建。
客户端使用php-pecl-memcache-3.0.5进行连接。
使用的代码如下
$cache = memcache_connect(MEMCACHE_HOST, MEMCACHE_PORT);
有时会发生$cache对象未创建的情况。
请指导我如何解决这个问题。谢谢。
最佳答案
试试这个:
<?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') . ']';
关于php - AWS elasticache 与 php 的连接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11125029/