简体   繁体   English

PHP Memcached会话副本问题

[英]PHP Memcached sessions replica issue

I have setup a couple of Memcached servers to use as PHP session storage, but despite trying various settings I'm unable to get the session keys to appear in both servers. 我已经设置了几个Memcached服务器用作PHP会话存储,但是尽管尝试了各种设置,但我无法让会话密钥出现在两个服务器中。

My php.ini is as follows: 我的php.ini如下:

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

My memcached.ini is variations of: 我的memcached.ini是以下变体:

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

If I run memcached using -vv I can see keys are being written to the first server: 如果我使用-vv运行memcached,我可以看到键被写入第一台服务器:

<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.

However the second server just gets connects/disconnects, but nothing is stored: 但是第二台服务器只是连接/断开,但没有存储:

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

So as soon as you kill the first server sessions are lost an there is no failover. 因此,只要您终止第一个服务器会话丢失,就没有故障转移。

Anyone know what's going on here? 谁知道这里发生了什么?

Edit: 编辑:

We created a few sessions in different browsers, it looks like the keys are being distributed, but not replicated. 我们在不同的浏览器中创建了几个会话,看起来密钥正在分发,但没有被复制。

Server 1: 服务器1:

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

Server 2: 服务器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]

It turns out that the version of memcached bundled with Ubuntu 14.04 (2.1.0) doesn't support the sess_number_of_replicas option. 事实证明,与Ubuntu 14.04(2.1.0)捆绑在一起的memcached版本不支持sess_number_of_replicas选项。 We installed the latest version from PECL and this solved the problem. 我们从PECL安装了最新版本,这解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM