简体   繁体   English

配置PHP Memcached会话进行集群

[英]Configuring PHP Memcached sessions for clustering

I already had a look to a few posts about this but can't get it to work 我已经看过一些关于此的帖子,但无法正常工作

I have 2 ubuntu servers, for testing, I installed the following: 我有2个ubuntu服务器,为了进行测试,我安装了以下服务器:

apt-get install memcached
apt-get install apache2
apt-get install php5
apt-get install libapache2-mod-php5
apt-get install php5-memcached

my /etc/memcached.conf has 我的/etc/memcached.conf有

Server 1 服务器1

-m -p 11211 -l 192.168.0.1

Server 2 服务器2

-m -p 11211 -l 192.168.0.2

my /etc/php5/apache2/php.ini 我的/etc/php5/apache2/php.ini

Server 1 服务器1

session.save_handler = memcached
session.save_path = "192.168.0.1:11211,192.168.0.2:11211"

Server 2 服务器2

session.save_handler = memcached
session.save_path = "192.168.0.2:11211,192.168.0.1:11211"

and my small test on both /var/www/ 和我对/ var / www /的小测试

session_start();

echo “Session save_handler is: “.ini_get(”session.save_handler”).”
“;
echo “Session save_path is: “.ini_get(”session.save_path”).”
“;

if(isset($_SESSION['KEY']))
{
echo “KEY found: “.$_SESSION['KEY'];
}
else
{
$_SESSION['KEY'] = ‘test’;
echo ‘KEY set to: ‘.$_SESSION['KEY'];
}

It works for each individual server, meaning it does save the session. 它适用于每台服务器,这意味着它确实保存了会话。 But i do not get the session "copy" in the opposite server (it starts a new session no matter what) 但是我没有在相对的服务器上获得会话“副本”(无论如何它都会启动一个新会话)

I really don't know if I have a whoopsie on the test code or if I'm missing a conf. 我真的不知道我是否对测试代码感到不满或是否错过了会议。 I also tried memcache (withouth d) and adding tcp:// to the paths, but the result is the exact sth 我也尝试了memcache(不带d)并将tcp://添加到路径中,但结果确实是……

Update: 更新:

To be more clear, I want my session to be saved on both servers, the problem is it only saves on their local memcqched, never on the remote one. 更清楚地说,我希望将会话保存在两台服务器上,问题是它只保存在本地memcqched上,而不保存在远程服务器上。 According to http://www.php.net/manual/en/memcache.ini.php it should be working 根据http://www.php.net/manual/en/memcache.ini.php,它应该可以正常工作

Memcached does not replicate data onto each server. Memcached不会将数据复制到每个服务器上。 You can increase memcache storage capacity by adding additional memcache servers, but it does not replicate. 您可以通过添加其他Memcache服务器来增加Memcache存储容量,但它不会复制。 If you want that functionality you should look into repcached. 如果您想要该功能,则应研究repcached。
http://repcached.lab.klab.org/ . http://repcached.lab.klab.org/

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

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