[英]PHP session and memcacheD
Everybody knows there are two extensions for memcache on PHP:大家都知道 PHP 上有两个 memcache 扩展:
You can use memcache the PHP extension as a session_handler for PHP like so:您可以使用内存缓存 PHP 扩展作为 PHP 的 session_handler,如下所示:
session.save_handler = memcache
session.save_path = "tcp://serv01:11211,tcp://serv02:11211,tcp://serv03:11211"
Or you can use memcached like so:或者您可以像这样使用 memcached:
session.save_handler = memcached
session.save_path = "serv01:11211,serv02:11211,serv03:11211"
But how to set other parameters to memcached such as:但是如何将其他参数设置为 memcached,例如:
In PHP I will do like so:在 PHP 我会这样做:
$cache = new Memcached();
$cache->addServer('serv01', 11211);
$cache->addServer('serv02', 11211);
$cache->addServer('serv03', 11211);
$cache->setOption(Memcached::OPT_HASH, Memcached::HASH_MD5);
$cache->setOption(Memcached::OPT_DISTRIBUTION, Memcached::DISTRIBUTION_CONSISTENT);
$cache->setOption(Memcached::OPT_CONNECT_TIMEOUT, 150);
$cache->setOption(Memcached::OPT_RETRY_TIMEOUT, 0);
But so far I have not found any documentation or examples of how to set those variables when they are use by the session_handler.但是到目前为止,我还没有找到任何文档或示例说明如何在 session_handler 使用这些变量时设置它们。
After looking trough the source code of both PECL extension and libmemcached itself I finally found my answer in the comment of the blog of the author of the memcached extension.在查看了 PECL 扩展和 libmemcached 本身的源代码后,我终于在 memcached 扩展作者的博客评论中找到了答案。
http://zmievski.org/2009/01/new-memcached-extension http://zmievski.org/2009/01/new-memcached-extension
I quote in case his blog disappeared some day:我引用以防他的博客有一天消失了:
Andrei said: @Ash, the session save path syntax is not quite the same as the other memcache extension.
Andrei 说: @Ash,session 保存路径语法与其他 memcache 扩展不太一样。 Try:
尝试:
session.save_path="127.0.0.1:11211"
session.save_path="127.0.0.1:11211"
Ash Searle said: Is there any documentation for the syntax – ie does it handle multiple servers and optional parameters like the earlier memcache implementations?
Ash Searle 说:是否有任何语法文档——即它是否像早期的 memcache 实现那样处理多个服务器和可选参数? (eg save_path="127.0.0.1:11211?persistent=1&timeout=1&retry_interval=15")
(例如 save_path="127.0.0.1:11211?persistent=1&timeout=1&retry_interval=15")
Andrei said: @Ash, no, it's not that advanced.
Andrei 说: @Ash,不,它没有那么先进。 For now, the syntax is the default one that libmemcached parser supports: basically, a comma-separated list of hostname:port entries, where:port is optional.
目前,语法是 libmemcached 解析器支持的默认语法:基本上,主机名:端口条目的逗号分隔列表,其中:端口是可选的。
OR或者
Rich Choy said: Is there a reference on the Web that explains each connection parameter that appears after host:port?
Rich Choy 说: Web 上是否有解释 host:port 之后出现的每个连接参数的参考? For example what exactly does “timeout=1″ mean?
例如,“timeout=1”究竟是什么意思?
Andrei said: @Rich, which extension are you using?
Andrei 说: @Rich,你用的是哪个扩展? :) Mine doesn't support those extra parameters, you must be talking about pecl/memcache one.
:) 我的不支持那些额外的参数,你一定是在谈论 pecl/memcache 之一。
AND和
Frank Orson said: 1) Does pecl/memcached support UDP on the client?
Frank Orson 说: 1)pecl/memcached 在客户端是否支持 UDP? I could not find any info about this.
我找不到有关此的任何信息。 I know that pecl/memcache 3.0.4 supports it.
我知道 pecl/memcache 3.0.4 支持它。
2) Does pecl/memcached have failover support in the client?
2) pecl/memcached 在客户端是否支持故障转移?
Andrei said: Frank, I'm working on next version (2.0) of the memcached extension.
Andrei 说: Frank,我正在开发 memcached 扩展的下一个版本(2.0)。 It'll have UDP support and replication (failover).
它将具有 UDP 支持和复制(故障转移)。
If you check the source code of version 2 you can see for example that you can append in the save_path string "PERSISTENT=" and "--SERVER" ((which I don't know how it would be used)如果您检查版本 2 的源代码,您可以看到例如您可以在 save_path 字符串“PERSISTENT=”和“--SERVER”中看到 append((我不知道它会如何使用)
You need to write your own session handler and wrap Memcache(d) methods around it.您需要编写自己的 session 处理程序并围绕它包装 Memcache(d) 方法。
http://www.php.net/manual/en/function.session-set-save-handler.php http://www.php.net/manual/en/function.session-set-save-handler.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.