我被要求在两台服务器上设置一个 Memcached 服务器(每台一台)。为了便于记录,我运行的是 PHP 5.6.5。以下是我的设置:
memcached.ini文件:
extension=memcached.so
memcache.allow_failover=1
memcache.session_redundancy=3
php -i | grep memcached
memcached support => enabled
libmemcached version => 1.0.16
memcached.compression_factor => 1.3 => 1.3
memcached.compression_threshold => 2000 => 2000
memcached.compression_type => fastlz => fastlz
memcached.serializer => php => php
memcached.sess_binary => 0 => 0
memcached.sess_connect_timeout => 1000 => 1000
memcached.sess_consistent_hash => 0 => 0
memcached.sess_lock_expire => 0 => 0
memcached.sess_lock_max_wait => 0 => 0
memcached.sess_lock_wait => 150000 => 150000
memcached.sess_locking => 1 => 1
memcached.sess_number_of_replicas => 0 => 0
memcached.sess_prefix => memc.sess.key. => memc.sess.key.
memcached.sess_randomize_replica_read => 0 => 0
memcached.sess_remove_failed => 0 => 0
memcached.sess_sasl_password => no value => no value
memcached.sess_sasl_username => no value => no value
memcached.store_retry_count => 2 => 2
memcached.use_sasl => 0 => 0
Registered save handlers => files user memcache memcached
session.save_handler => memcached => memcached
php.ini
session.save_handler = memcached
session.save_path = 'tcp://10.109.6.122:11211,tcp://10.105.164.25:11211'
但是,我似乎遇到了服务器冗余问题。就在下面,我有一个我选择测试的测试网格。WAS
是一台 Apache 服务器,MEMCACHE
是同时运行的 Memcached 服务器。
+---------+------------+---------+------------+
| WAS1 | MEMCACHED1 | WAS2 | MEMCACHED2 |
+---------+------------+---------+------------+
| Started | Started | Stopped | Stopped |
| Stopped | Stopped | Started | Started |
| Started | Stopped | Stopped | Started |
| Stopped | Started | Started | Stopped |
+---------+------------+---------+------------+
下面是我用来测试的代码。重点是,应该$session->id
可以毫无问题地增加。
<?php
require_once "cron_init.php";
$session = new Zend_Session_Namespace('lastCommande');
$session->type = 'test';
if (!isset($session->id)) {
$session->id = 1;
echo "Première visite par ici \n" ;
}
else {
echo "Nombre de visite pour l'instant : " . $session->id . "\n";
$session->id++;
}
print_r($_COOKIE);
理论上,一切都运行正常。当我“关闭”其中一台服务器(其中一台服务器上的 Apache + Memcached)时,我得到的数字不断增加,但根据我停止的 Memcached 服务器(主要是Memcached1
),我得到的递增数字不正确。
例如,如果我恰好停止Memcached1
,Memcache2
将有其自己的数据。此时,$session->id
为 18 Memcached1
, 为 14,Memcached2
而它们应该都为 14 或 18。
由于这个已知的 PHP 错误,我尝试了这两种memcache.session_redundancy=2
方法memcache.session_redundancy=3
,但无论如何问题仍然存在。
我还可以做些什么?
先感谢您
答案1
由于您似乎正在使用memcached
而不是memcache
,因此您应该使用以下设置:
memcached.sess_number_of_replicas = 3
memcached.sess_binary_protocol = 1