Timeout faster \w memcache
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 t开发者_如何学Co 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.
Just call:
Memcache::getServerStatus()
orMemcache::getExtendedStats()
Also, this question is pretty much identical to yours.
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:
$memcache->connect('memcache_host', 11211, $timeout);
however the default timeout should be already set to 1 second.
Another place to look are TCP timeout parameters in OS.
精彩评论