(PECL memcache >= 2.0.0)
Memcache::addServer -- memcache_add_server — Add a memcached server to connection pool
$host,$port = 11211,$persistent = ?,$weight = ?,$timeout = ?,$retry_interval = ?,$status = ?,$failure_callback = ?,$timeoutms = ?$memcache,$host,$port = 11211,$persistent = ?,$weight = ?,$timeout = ?,$retry_interval = ?,$status = ?,$failure_callback = ?,$timeoutms = ?Memcache::addServer() adds a server to the connection pool.
When using this method (as opposed to Memcache::connect() and Memcache::pconnect()) the network connection is not established until actually needed. Thus there is no overhead in adding a large number of servers to the pool, even though they might not all be used.
Failover may occur at any stage in any of the methods, as long as other servers are available the request the user won't notice. Any kind of socket or Memcached server level errors (except out-of-memory) may trigger the failover. Normal client errors such as adding an existing key will not trigger a failover.
Note: This function has been added to Memcache version 2.0.0.
hostunix:///path/to/memcached.sock to use UNIX domain sockets, in this case port must also be set to 0.port0 when using UNIX domain sockets. Please note: port defaults to memcache.default_port if not specified. For this reason it is wise to specify the port explicitly in this method call.persistenttrue.weighttimeoutretry_intervalpersistent parameter has any effect when the extension is loaded dynamically via dl(). Each failed connection struct has its own timeout and before it has expired the struct will be skipped when selecting backends to serve a request. Once expired the connection will be successfully reconnected or marked as failed for another retry_interval seconds. The typical effect is that each web server child will retry the connection about every retry_interval seconds when serving a page.statusfalse and retry_interval to -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 the memcache.allow_failover setting. Default to true, meaning the server should be considered online.failure_callbacktimeoutmsExample #1 Memcache::addServer() example
<?php
/* OO API */
$memcache = new Memcache;
$memcache->addServer('memcache_host', 11211);
$memcache->addServer('memcache_host2', 11211);
/* procedural API */
$memcache_obj = memcache_connect('memcache_host', 11211);
memcache_add_server($memcache_obj, 'memcache_host2', 11211);
?>When the port is unspecified, this method defaults to the value set of the PHP ini directive memcache.default_port If this value was changed elsewhere in your application it might lead to unexpected results: for this reason it is wise to always specify the port explicitly in this method call.