php - AWS elasticache 与 php 的连接问题

标签 php memcached amazon-elasticache

我正在 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/

相关文章:

PHP Curl 未在适用于 Windows 8.1 64 位的 PHP 7.3.3 中加载

php - 一次播种多行 laravel 5

php - PHPUnit 是否有一些内置的递归数组比较功能?

php - AWS DynamoDB session 与 Elasticache PHP session

php - memcache php 缓存 js css 和图像

amazon-web-services - Elasticache 和可用区

php - Laravel contains() 用于多个值

node.js - 当来自 AWS ElastiCache Redis 的 'get' 时,nodejs 中的 ioredis 不执行任何操作

amazon-web-services - 如何在不使用 NAT 网关的情况下从 aws-lambda 连接 elasticache 和 dynamoDb

php - fatal error : Class 'Memcache' not found (installed with pecl)