<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.memcached.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'memcached.addserver.php',
    1 => 'Memcached::addServer',
    2 => '向服务器池增加服务器',
  ),
  'up' => 
  array (
    0 => 'class.memcached.php',
    1 => 'Memcached',
  ),
  'prev' => 
  array (
    0 => 'memcached.addbykey.php',
    1 => 'Memcached::addByKey',
  ),
  'next' => 
  array (
    0 => 'memcached.addservers.php',
    1 => 'Memcached::addServers',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/memcached/memcached/addserver.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="memcached.addserver" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Memcached::addServer</h1>
  <p class="verinfo">(PECL memcached &gt;= 0.1.0)</p><p class="refpurpose"><span class="refname">Memcached::addServer</span> &mdash; <span class="dc-title">向服务器池增加服务器</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-memcached.addserver-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>Memcached::addServer</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$host</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$port</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$weight</code><span class="initializer"> = 0</span></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>Memcached::addServer()</strong></span> 增加指定服务器到服务器池。此时不会与服务端建立连接，但如果使用一致性
   key 分发选项（<strong><code><a href="memcached.constants.php#memcached.constants.distribution-consistent">Memcached::DISTRIBUTION_CONSISTENT</a></code></strong> 或
   <strong><code><a href="memcached.constants.php#memcached.constants.opt-libketama-compatible">Memcached::OPT_LIBKETAMA_COMPATIBLE</a></code></strong>），则必须更新一些内部的数据结构。 因此，如果需要增加多台服务器，最好使用
   <span class="methodname"><a href="memcached.addservers.php" class="methodname">Memcached::addServers()</a></span> 以确保这种更新只发生一次。
  </p>
  <p class="para">
   同一台服务器可以在服务器池中多次出现，因为没有做重复检测。但并不推荐这样做，对于期望提高某台服务器的权重，请使用
   <code class="parameter">weight</code> 参数。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-memcached.addserver-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">host</code></dt>
     <dd>
      <p class="para">
       memcached 服务端主机名。如果主机名无效，相关的数据操作的结果代码将被设置为
       <strong><code><a href="memcached.constants.php#memcached.constants.res-host-lookup-failure">Memcached::RES_HOST_LOOKUP_FAILURE</a></code></strong>。从 2.0.0b1 版本开始，这个参数还可以指定 unix
       套接字文件的路径。例如：<code class="literal">/path/to/memcached.sock</code> 使用 UNIX 域套接字，在这种情况下
       <code class="parameter">port</code> 也必须设置为 <code class="literal">0</code>。
      </p>
     </dd>
    
    
     <dt><code class="parameter">port</code></dt>
     <dd>
      <p class="para">
       运行 memcached 的端口号，通常是 <code class="literal">11211</code>。从版本 2.0.0b1
       开始，在使用 UNIX 域套接字时将此参数设置为 <code class="literal">0</code>。
      </p>
     </dd>
    
    
     <dt><code class="parameter">weight</code></dt>
     <dd>
      <p class="para">
       此服务器相对于服务器池中所有服务器的权重。此参数用来控制服务器在操作时被选中的概率。这个仅用于一致性分布选项，并且这个值通常是由服务端分配的内存来设置的。
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-memcached.addserver-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>， 或者在失败时返回 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-memcached.addserver-examples">
  <h3 class="title">示例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>示例 #1 <span class="function"><strong>Memcached::addServer()</strong></span> 示例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?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">-&gt;</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">-&gt;</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">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-memcached.addserver-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="memcached.addservers.php" class="methodname" rel="rdfs-seeAlso">Memcached::addServers()</a> - 向服务器池中增加多台服务器</span></li>
    <li><span class="methodname"><a href="memcached.resetserverlist.php" class="methodname" rel="rdfs-seeAlso">Memcached::resetServerList()</a> - Clears all servers from the server list</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>