使用PHP-memcache对memcached进行会话故障转移 [英] Sessions Failover with PHP-memcache against memcached

查看:109
本文介绍了使用PHP-memcache对memcached进行会话故障转移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

同事!

我正在运行带有memcache(2.2.6)客户端库(http://pecl.php.net/package/memcache)的php 5.3(5.3.8),以处理memcached服务器. 我的目标是为会话引擎提供故障转移解决方案,即:

I'm running php 5.3 (5.3.8) with memcache (2.2.6) client library (http://pecl.php.net/package/memcache) to deal with memcached server. My goal is to have failover solution for sessions engine, namely:

  • 仅支持本机php会话(无自定义处理程序)
  • 池中很少有Memcached服务器

我期望的是,如果其中一个Memcached服务器关闭,则php将尝试利用池中的第二个服务器[将成功连接它并变得很高兴],但是当池中的第一个memcached服务器关闭时,我收到以下错误:

What I expect is that in case if one of memcached servers is down, php will attempt to utilize the second server in the pool [will successfully connect it and become happy], however when first memcached server in the pool is down I'm receiving the following error:

Session start failed. Original message: session_start(): Server 10.0.10.111 (tcp 11211) failed with: Connection refused (111)

相关的php设置为:

session.save_handler memcache
session.save_path tcp://10.0.10.111:11211?persistent=1&weight=1&timeout=1&retry_interval=10, tcp://10.0.10.110:11211?persistent=1&weight=1&timeout=1&retry_interval=10

和memcache设置(虽然我认为它接近标准)是:

and memcache settings (while I think that it's near to standard) are:

Directive   Local Value
memcache.allow_failover 1
memcache.chunk_size 8192
memcache.default_port   11211
memcache.default_timeout_ms 1000
memcache.hash_function  crc32
memcache.hash_strategy  standard
memcache.max_failover_attempts  20

Memcached仍在第二台服务器上运行,并且可以从WEB服务器完全访问:

Memcached still running on the second server and perfectly accessible from the WEB server:

telnet 10.0.10.110  11211
Trying 10.0.10.110...
Connected to 10.0.10.110 (10.0.10.110).
Escape character is '^]'.
get aaa
END
quit
Connection closed by foreign host.

因此,换句话说,它没有顺序查询所有列出的服务器,而是在尝试连接队列中的第一台服务器失败后崩溃.最后,我的确意识到有可用的3.0.x客户端库版本,但是对于我来说,它看起来仍然不太可靠,因为它仍处于beta版本.

So in other words, instead of querying all of the listed servers sequentially it crashes after unsuccessful attempt to connect the first server in the queue. Finally I do realize that there are releases of 3.0.x client library available, however it does not look too reliable for me as it still in beta version.

请告知我如何使用标准PHP,客户端库和服务器来获得所需的行为.

Please advice how can I get desired behavior with standard PHP, client lib and server.

非常感谢!

最好, 尤金

推荐答案

我要感谢参与此问题的每个人,答案如下:实际上,memcache(不是memcache d )为会话处理程序支持 逗号分隔的服务器作为session.save_path,此外,它还支持故障转移.上面提到的错误Session start failed. Original message: session_start(): Server 10.0.10.111 (tcp 11211) failed with: Connection refused (111)仅具有第8级(通知).实际上,引擎只是告知您其中一台服务器不可用(这是逻辑的,否则您将如何知道?),然后成功连接到第二台服务器并使用它.

I would like to thank everybody who participated this question, the answer is the following: in reality memcache (not memcached) as session handler supports comma separated servers as the session.save_path, moreover it supports failover. The error mentioned above Session start failed. Original message: session_start(): Server 10.0.10.111 (tcp 11211) failed with: Connection refused (111) had only 8th (Notice) level. In fact engine just informs you about the fact that one of the servers is unavailable (which is logical, as otherwise how will you know?) and then successfully connects to the second server and using it.

因此,所有误解都是由于文档薄弱,memcache/memcached混乱以及自定义错误处理程序的偏执(E_ALL)设置引起的.同时,该问题已通过在会话建立上下文中忽略有关错误Connection refused (111)的通知而得到解决

So all of the misunderstanding has been caused by weak documentation, memcache/memcached confusions and paranoid (E_ALL) settings of my custom error handler. In the meantime the issue has been resolved by ignoring notices referring to error Connection refused (111) in the session establishing context

这篇关于使用PHP-memcache对memcached进行会话故障转移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆