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.

注意:

This function has been added to Memcache version 2.0.0.

参数

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

返回值

如果成功则返回 TRUE,失败则返回 FALSE

范例

例 1107. 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);

?>