<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Add a server to the server pool</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="memcached.addbykey.html">Memcached::addByKey</a></div> <div class="next" style="text-align: right; float: right;"><a href="memcached.addservers.html">Memcached::addServers</a></div> <div class="up"><a href="class.memcached.html">Memcached</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="memcached.addserver" class="refentry"> <div class="refnamediv"> <h1 class="refname">Memcached::addServer</h1> <p class="verinfo">(PECL memcached >= 0.1.0)</p><p class="refpurpose"><span class="refname">Memcached::addServer</span> — <span class="dc-title">Add a server to the server pool</span></p> </div> <div class="refsect1 description" id="refsect1-memcached.addserver-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">bool</span> <span class="methodname"><strong>Memcached::addServer</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$host</code></span> , <span class="methodparam"><span class="type">int</span> <code class="parameter">$port</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$weight</code><span class="initializer"> = 0</span></span> ] )</div> <p class="para rdfs-comment"> <span class="function"><strong>Memcached::addServer()</strong></span> adds the specified server to the server pool. No connection is established to the server at this time, but if you are using consistent key distribution option (via <strong><code>Memcached::DISTRIBUTION_CONSISTENT</code></strong> or <strong><code>Memcached::OPT_LIBKETAMA_COMPATIBLE</code></strong>), some of the internal data structures will have to be updated. Thus, if you need to add multiple servers, it is better to use <span class="methodname"><a href="memcached.addservers.html" class="methodname">Memcached::addServers()</a></span> as the update then happens only once. </p> <p class="para"> The same server may appear multiple times in the server pool, because no duplication checks are made. This is not advisable; instead, use the <em><code class="parameter">weight</code></em> option to increase the selection weighting of this server. </p> </div> <div class="refsect1 parameters" id="refsect1-memcached.addserver-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">host</code></em></span> <dd> <p class="para"> The hostname of the memcache server. If the hostname is invalid, data-related operations will set <strong><code>Memcached::RES_HOST_LOOKUP_FAILURE</code></strong> result code. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">port</code></em></span> <dd> <p class="para"> The port on which memcache is running. Usually, this is <em>11211</em>. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">weight</code></em></span> <dd> <p class="para"> 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. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-memcached.addserver-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on failure. </p> </div> <div class="refsect1 examples" id="refsect1-memcached.addserver-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-4428"> <p><strong>Example #1 <span class="function"><strong>Memcached::addServer()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$m </span><span style="color: #007700">= new </span><span style="color: #0000BB">Memcached</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/* Add 2 servers, so that the second one<br /> is twice as likely to be selected. */<br /></span><span style="color: #0000BB">$m</span><span style="color: #007700">-></span><span style="color: #0000BB">addServer</span><span style="color: #007700">(</span><span style="color: #DD0000">'mem1.domain.com'</span><span style="color: #007700">, </span><span style="color: #0000BB">11211</span><span style="color: #007700">, </span><span style="color: #0000BB">33</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$m</span><span style="color: #007700">-></span><span style="color: #0000BB">addServer</span><span style="color: #007700">(</span><span style="color: #DD0000">'mem2.domain.com'</span><span style="color: #007700">, </span><span style="color: #0000BB">11211</span><span style="color: #007700">, </span><span style="color: #0000BB">67</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-memcached.addserver-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="methodname"><a href="memcached.addservers.html" class="methodname" rel="rdfs-seeAlso">Memcached::addServers()</a> - Add multiple servers to the server pool</span></li> <li class="member"> <span class="methodname"><a href="memcached.resetserverlist.html" class="methodname" rel="rdfs-seeAlso">Memcached::resetServerList()</a> - Clears all servers from the server list</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="memcached.addbykey.html">Memcached::addByKey</a></div> <div class="next" style="text-align: right; float: right;"><a href="memcached.addservers.html">Memcached::addServers</a></div> <div class="up"><a href="class.memcached.html">Memcached</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>