Timeout faster \ w memcache

I try to force PHP to memcache the timeout extension almost immediately if the memcached server to which I connect is connected (for some reason). I would like to make an exception in this case (which will be handled elsewhere).

I searched and tried different things without any luck. I am adding servers (only one so far) to the standard pool:

$this->memcache->addServer ( $server['host'], $server['port'] );

Then I killed memcached deamon (also tried with the wrong port and host) and opened my page. It just loads for a very long time, and then nginx returns with a 504 Gateway Time-out error.

How can I tell the memcache client to try, I don’t know, 1 second, and then give up, and at that moment I must somehow find the timeout.

The bottom line is that if our memcached server is unavailable, I would like to display a user-friendly error page as soon as possible (already working on uncaught exceptions) and not force the user to wait 30 seconds before he sees a general server error.

+4
source share
2 answers

Just call:

Also, this question is pretty much identical to yours.

+4
source

Decrease the value of the max_failover_attempts parameter of the memcache module configuration parameter, the default value is too large.

You can also specify a timeout as the 3rd parameter of connect() :

 $memcache->connect('memcache_host', 11211, $timeout); 

however, the default timeout should already be set to 1 second.

Another place to look is the TCP timeout settings on the OS.

+3
source

All Articles