gpt4 book ai didi

apache - PHP session 和 memcacheD

转载 作者:IT王子 更新时间:2023-10-29 00:18:18 25 4
gpt4 key购买 nike

每个人都知道 PHP 上的 memcache 有两个扩展:

  • 内存缓存
  • 内存缓存

您可以像这样使用 PHP 扩展的 memcache 作为 PHP 的 session 处理程序:

session.save_handler = memcache
session.save_path = "tcp://serv01:11211,tcp://serv02:11211,tcp://serv03:11211"

或者您可以像这样使用 memcached:

session.save_handler = memcached
session.save_path = "serv01:11211,serv02:11211,serv03:11211"

但是如何给memcached设置其他参数比如:

  • 内存缓存::OPT_DISTRIBUTION
  • 内存缓存::OPT_RETRY_TIMEOUT
  • 内存缓存::OPT_CONNECT_TIMEOUT

在 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);

但到目前为止,我还没有找到任何文档或示例来说明如何在 session_handler 使用这些变量时设置这些变量。

最佳答案

在查看了 PECL 扩展和 libmemcached 本身的源代码后,我终于在 memcached 扩展作者的博客评论中找到了答案。

http://zmievski.org/2009/01/new-memcached-extension

我引用以防有一天他的博客消失了:

Andrei said: @Ash, the session save path syntax is not quite the same as the other memcache extension. Try:

session.save_path="127.0.0.1:11211"

Ash Searle said: Is there any documentation for the syntax – i.e. does it handle multiple servers and optional parameters like the earlier memcache implementations? (e.g. save_path="127.0.0.1:11211?persistent=1&timeout=1&retry_interval=15")

Andrei said: @Ash, no, it’s not that advanced. 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.

Rich Choy said: Is there a reference on the Web that explains each connection parameter that appears after host:port? For example what exactly does “timeout=1″ mean?

Andrei said: @Rich, which extension are you using? :) Mine doesn’t support those extra parameters, you must be talking about pecl/memcache one.

Frank Orson said: 1) Does pecl/memcached support UDP on the client? I could not find any info about this. I know that pecl/memcache 3.0.4 supports it.

2) Does pecl/memcached have failover support in the client?

Andrei said: Frank, I’m working on next version (2.0) of the memcached extension. It’ll have UDP support and replication (failover).

如果您查看版本 2 的源代码,您会看到例如您可以在 save_path 字符串中附加“PERSISTENT=”和“--SERVER”((我不知道它会如何使用)

关于apache - PHP session 和 memcacheD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6668803/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com