Memcache::addServer

(no version information, might be only in CVS)

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

Description

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.

Note: This function has been added to Memcache version 2.0.0.

Parameters

host

Point to the host where memcached is listening for connections.

port

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

persistent

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

weight

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.

timeout

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.

retry_interval

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().

Return Values

Returns TRUE on success or FALSE on failure.

Examples

Example 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);

?>

See Also

Memcache::connect()
Memcache::pconnect()
Memcache::close()