【问题标题】:Aws elasticache connection issues with phpphp的AWS elasticache连接问题
【发布时间】:2012-06-22 21:54:16
【问题描述】:

我在 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 memcached amazon-elasticache


    【解决方案1】:

    试试这个:

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

    【讨论】:

      【解决方案2】:

      现在使用更新版本的 memcached(当前为 1.4.14),我认为连接问题可能是由于 1.4.5 版本的 memcache 中的错误造成的。

      【讨论】:

        猜你喜欢
        • 2016-09-15
        • 1970-01-01
        • 2015-12-22
        • 2013-01-10
        • 2018-12-04
        • 2017-05-23
        • 2020-11-01
        • 2022-01-02
        • 2021-06-12
        相关资源
        最近更新 更多