2014-07-25 128 views
6

我已經設置了幾個Memcached服務器用作PHP會話存儲,但儘管嘗試了各種設置,我無法讓會話密鑰出現在兩臺服務器中。PHP Memcached會話副本問題

我的php.ini如下:

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

我memcached.ini是變體:如果我運行使用-vv

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

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. 

但是,第二臺服務器只是連接/斷開連接,但沒有存儲任何內容:

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

因此,只要你殺了第一個服務器會話丟失,就沒有故障轉移。

任何人都知道這裏發生了什麼?

編輯:

我們創造了不同的瀏覽器經過一個階段,它看起來像按鍵被分散,而不是複製。

服務器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] 

回答

7

事實證明,在Ubuntu 14.04(2.1.0)捆綁分佈式緩存的版本不支持sess_number_of_replicas選項。我們安裝了PECL的最新版本,解決了這個問題。