Memcached::addServer
Add a server to the server pool
Description
public bool Memcached::addServer(string $host
, int $port
, int $weight
= 0)
The same server may appear multiple times in the server pool, because no
duplication checks are made. This is not advisable; instead, use the
weight
option to increase the selection weighting of
this server.
Parameters
-
host
-
The hostname of the memcache server. If the hostname is invalid,
data-related operations will set
Memcached::RES_HOST_LOOKUP_FAILURE
result code. As
of version 2.0.0b1, this parameter may also specify the path of a unix
socket filepath ex. /path/to/memcached.sock
to use UNIX domain sockets, in this case port
must also be set to 0
.
-
port
-
The port on which memcache is running. Usually, this is
11211
. As of version 2.0.0b1, set this parameter to 0
when
using UNIX domain sockets.
-
weight
-
The weight of the server relative to the total weight of all the
servers in the pool. This controls the probability of the server being
selected for operations. This is used only with consistent distribution
option and usually corresponds to the amount of memory available to
memcache on that server.
Return Values
Returns true
on success or false
on failure.
Examples
Example #1 Memcached::addServer example
<?php
$m = new Memcached();
/* Add 2 servers, so that the second one
is twice as likely to be selected. */
$m->addServer('mem1.domain.com', 11211, 33);
$m->addServer('mem2.domain.com', 11211, 67);
?>
See Also
- Memcached::addServers
- Memcached::resetServerList