PHP Memcached session 副本问题

标签 php session memcached

我已经设置了几个 Memcached 服务器用作 PHP session 存储,但尽管尝试了各种设置,但我无法让 session key 出现在两个服务器中。

我的php.ini如下:

session.save_handler = memcached
session.save_path = "192.168.134.38:11211,192.168.134.234:11211"

我的 memcached.ini 是以下的变体:

extension=memcached.so
memcached.sess_consistent_hash=1
memcached.sess_number_of_replicas=1
memcached.sess_binary=1

如果我使用 -vv 运行 memcached,我可以看到正在将 key 写入第一台服务器:

<30 new auto-negotiating client connection
30: Client using the binary protocol
<30 Read binary protocol data:
<30    0x80 0x0c 0x00 0x28
<30    0x00 0x00 0x00 0x00
<30    0x00 0x00 0x00 0x28
<30    0x00 0x00 0x00 0x00
<30    0x00 0x00 0x00 0x00
<30    0x00 0x00 0x00 0x00
<30 GET memc.sess.key.9bn8cdu9c1j7ko1tmflgr433k1
>30 Writing bin response:
>30   0x81 0x0c 0x00 0x28
>30   0x04 0x00 0x00 0x00
>30   0x00 0x00 0x03 0xc6
>30   0x00 0x00 0x00 0x00
>30   0x00 0x00 0x00 0x00
>30   0x00 0x00 0x00 0x00
<30 Read binary protocol data:
<30    0x80 0x01 0x00 0x28
<30    0x08 0x00 0x00 0x00
<30    0x00 0x00 0x03 0xcb
<30    0x00 0x00 0x00 0x00
<30    0x00 0x00 0x00 0x00
<30    0x00 0x00 0x00 0x00
<30 SET memc.sess.key.9bn8cdu9c1j7ko1tmflgr433k1 Value len is 923
>30 Writing bin response:
>30   0x81 0x01 0x00 0x00
>30   0x00 0x00 0x00 0x00
>30   0x00 0x00 0x00 0x00
>30   0x00 0x00 0x00 0x00
>30   0x00 0x00 0x00 0x00
>30   0x00 0x00 0x00 0x05
<30 Read binary protocol data:
<30    0x80 0x07 0x00 0x00
<30    0x00 0x00 0x00 0x00
<30    0x00 0x00 0x00 0x00
<30    0x00 0x00 0x00 0x00
<30    0x00 0x00 0x00 0x00
<30    0x00 0x00 0x00 0x00
>30 Writing bin response:
>30   0x81 0x07 0x00 0x00
>30   0x00 0x00 0x00 0x00
>30   0x00 0x00 0x00 0x00
>30   0x00 0x00 0x00 0x00
>30   0x00 0x00 0x00 0x00
>30   0x00 0x00 0x00 0x00
<30 connection closed.

然而,第二个服务器只是连接/断开连接,但没有存储任何内容:

<30 new auto-negotiating client connection
30: Client using the ascii protocol
<30 quit
<30 connection closed.

因此,一旦您终止第一个服务器 session 就会丢失,并且没有故障转移。

有人知道这里发生了什么吗?

编辑:

我们在不同的浏览器中创建了几个 session ,看起来 key 正在分发,但没有复制。

服务器 1:

stats cachedump 12 100
ITEM memc.sess.key.80iie5lhm36mddkekdk488q923 [922 b; 1406287763 s]

服务器 2:

stats cachedump 12 100
ITEM memc.sess.key.ehd1nsm6icc2qsotbkcp8i9sd7 [874 b; 1406287898 s]
ITEM memc.sess.key.d3p0id333ggbd0004n4rcc4890 [875 b; 1406287868 s]
ITEM memc.sess.key.7hek9e2aakgqv9sm2bcq5fbfb3 [922 b; 1406287842 s]

最佳答案

事实证明,与 Ubuntu 14.04 (2.1.0) 捆绑的 memcached 版本不支持 sess_number_of_replicas 选项。我们安装了 PECL 的最新版本,这解决了问题。

关于PHP Memcached session 副本问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24953136/

相关文章:

java - memcached 中存储了什么?

mysql - NodeJS、Redis 和 MySQL

php - 从类打印或从函数返回输出和打印之间有什么区别

php - 使用 mysql 存储的安全 php session 处理

php - 将 .CSV 文件导入 mysql 数据库

php - 从一个页面获取 PHP 变量到另一个

.net - 如何清除客户端 .Net SSL session 缓存

php - MVC 框架中的缓存策略?

php - 我如何找到 Zend 在我的服务器上的安装位置?

java - 如果管理层决定开源项目可以满足业务需求。您(Java开发人员)会学习PHP吗?