超时更快 \w memcache
我试图强制 PHP 的 Memcache 扩展 如果 memcached 服务器几乎立即超时我正在连接到不可用(无论出于何种原因)。我想在这种情况下引发异常(将在其他地方处理)。
我一直在寻找并尝试不同的东西,但没有任何运气。我正在使用以下标准将服务器(目前只有一台)添加到池中:
$this->memcache->addServer ( $server['host'], $server['port'] );< /code>
然后我杀死了 memcached 守护进程(也尝试使用错误的端口和主机)并打开我的页面。它只是加载了很长一段时间,然后 nginx 返回了 504 Gateway Time-out
错误。
我怎样才能告诉memcache客户端尝试,我不知道,1秒然后放弃,此时我应该能够以某种方式检测到超时。
最重要的是,如果我们的 memcached 服务器宕机,我希望尽快显示一个用户友好的错误页面(已经可以处理未捕获的异常),而不是让用户等待 30 秒才能看到通用服务器错误。
I'm trying to force PHP's Memcache extension to timeout almost immediately if a memcached server I'm connecting to isn't available (for whatever reason). I'd like to throw an exception in this case (which will be handled somewhere else).
I've been searching and trying different things without any luck. I'm adding servers (only one for now) to the pool with the standard:
$this->memcache->addServer ( $server['host'], $server['port'] );
I then killed the memcached deamon (also tried with a wrong port&host) and opened my page. It just loads for a very long time and then nginx comes back with a 504 Gateway Time-out
error.
How can I tell the memcache client to try for, I don't know, 1 second and then give up, at which point I should be able to detect the timeout somehow.
The bottom line is that if our memcached server would be down I'd like to display a user-friendly error page (already working for uncaught exceptions) as soon as possible and not make the user wait for 30 sec before he sees a generic server error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需调用:
Memcache::getServerStatus()
或Memcache::getExtendedStats()
另外,这个问题与您的问题几乎相同。
Just call:
Memcache::getServerStatus()
orMemcache::getExtendedStats()
Also, this question is pretty much identical to yours.
减少
max_failover_attempts 的值
memcache模块配置参数,默认数字太高。您还可以将超时指定为
connect()
方法:但是默认超时应该已设置为 1 秒。
另一个需要注意的地方是操作系统中的 TCP 超时参数。
Reduce the the value of
max_failover_attempts
memcache module configuration parameter, default number is too high.You can also specify timeout as 3rd parameter to
connect()
method:however the default timeout should be already set to 1 second.
Another place to look are TCP timeout parameters in OS.