Memcache::setServerParams
(PECL memcache >= 2.1.0)
Changes server parameters and status at runtime
Description
Memcache::setServerParams() changes server parameters at runtime.
This function has been added to Memcache version 2.1.0.
Parameters
hostPoint to the host where memcached is listening for connections.
portPoint to the port where memcached is listening for connections.
timeoutValue in seconds which will be used for connecting to the daemon. Think twice before changing the default value of 1 second - you can lose all the advantages of caching if your connection is too slow.
retry_intervalControls how often a failed server will be retried, the default value is 15 seconds. Setting this parameter to -1 disables automatic retry. Neither this nor the
persistentparameter has any effect when the extension is loaded dynamically viadl().statusControls if the server should be flagged as online. Setting this parameter to false and
retry_intervalto -1 allows a failed server to be kept in the pool so as not to affect the key distribution algorithm. Requests for this server will then failover or fail immediately depending on thememcache.allow_failoversetting. Default to true, meaning the server should be considered online.failure_callbackAllows the user to specify a callback function to run upon encountering an error. The callback is run before failover is attempted. The function takes two parameters, the hostname and port of the failed server.
Return Values
Success
Examples
Memcache::setServerParams() example
<?php
function _callback_memcache_failure($host, $port) {
print "memcache '$host:$port' failed";
}
/* OO API */
$memcache = new Memcache;
// Add the server in offline mode
$memcache->addServer('memcache_host', 11211, false, 1, 1, -1, false);
// Bring the server back online
$memcache->setServerParams('memcache_host', 11211, 1, 15, true, '_callback_memcache_failure');
/* procedural API */
$memcache_obj = memcache_connect('memcache_host', 11211);
memcache_set_server_params($memcache_obj, 'memcache_host', 11211, 1, 15, true, '_callback_memcache_failure');
?>