(no version information, might be only in CVS)

Memcache::addServer -- Add a memcached server to connection pool


bool Memcache::addServer ( string host [, int port [, bool persistent [, int weight [, int timeout [, int retry_interval]]]]] )

Memcache::addServer() adds a server to the connection pool. The actual connection is established on first use. The connection, which was opened using Memcache::addServer() will be automatically closed at the end of script execution. Also you can close it with Memcache::close(). You can also use the memcache_add_server() function.

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.



Point to the host where memcached is listening for connections.


Point to the port where memcached is listening for connections. This parameter is optional and its default value is 11211.


Controls the use of a persistent connection. Default to TRUE.


Number of buckets to create for this server which in turn control its probability of it being selected. The probability is relative to the total weight of all servers.


Value in seconds which will be used for connecting to the daemon. Think twice before changing the default value of 1 second - you can loose all the advantages of caching if your connection is too slow.


Controls how often a failed server will be retried, the default value is 15 seconds. Neither this nor the persistent parameter has any effect when this 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 webserver child will retry the connection about every retry_interval seconds when serving a page.

Return Values

Returns TRUE on success or FALSE on failure.


Example 1. Memcache::addServer() example


/* 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);


See Also


© Copyright 2003-2014 The ultimate PHP Editor and PHP IDE site.