<?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 => 'en',
  ),
  'this' => 
  array (
    0 => 'memcached.getserverbykey.php',
    1 => 'Memcached::getServerByKey',
    2 => 'Map a key to a server',
  ),
  'up' => 
  array (
    0 => 'class.memcached.php',
    1 => 'Memcached',
  ),
  'prev' => 
  array (
    0 => 'memcached.getresultmessage.php',
    1 => 'Memcached::getResultMessage',
  ),
  'next' => 
  array (
    0 => 'memcached.getserverlist.php',
    1 => 'Memcached::getServerList',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/memcached/memcached/getserverbykey.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="memcached.getserverbykey" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Memcached::getServerByKey</h1>
  <p class="verinfo">(PECL memcached &gt;= 0.1.0)</p><p class="refpurpose"><span class="refname">Memcached::getServerByKey</span> &mdash; <span class="dc-title">Map a key to a server</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-memcached.getserverbykey-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>Memcached::getServerByKey</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$server_key</code></span>): <span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>Memcached::getServerByKey()</strong></span> returns the server that
   would be selected by a particular <code class="parameter">server_key</code> in all
   the <span class="function"><strong>Memcached::*ByKey()</strong></span> operations.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-memcached.getserverbykey-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">server_key</code></dt>
     <dd>
      <p class="para">
       The key identifying the server to store the value on or retrieve it from. Instead of hashing on the actual key for the item, we hash on the server key when deciding which memcached server to talk to. This allows related items to be grouped together on a single server for efficiency with multi operations.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-memcached.getserverbykey-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns an array containing three keys of <code class="literal">host</code>,
   <code class="literal">port</code>, and <code class="literal">weight</code> on success or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on failure.
   Use <span class="methodname"><a href="memcached.getresultcode.php" class="methodname">Memcached::getResultCode()</a></span> if necessary.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-memcached.getserverbykey-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>Memcached::getServerByKey()</strong></span> example</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 /></span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addServers</span><span style="color: #007700">(array(<br />    array(</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">40</span><span style="color: #007700">),<br />    array(</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">40</span><span style="color: #007700">),<br />    array(</span><span style="color: #DD0000">'mem3.domain.com'</span><span style="color: #007700">, </span><span style="color: #0000BB">11211</span><span style="color: #007700">, </span><span style="color: #0000BB">20</span><span style="color: #007700">),<br />));<br /><br /></span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setOption</span><span style="color: #007700">(</span><span style="color: #0000BB">Memcached</span><span style="color: #007700">::</span><span style="color: #0000BB">OPT_LIBKETAMA_COMPATIBLE</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getServerByKey</span><span style="color: #007700">(</span><span style="color: #DD0000">'user'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getServerByKey</span><span style="color: #007700">(</span><span style="color: #DD0000">'log'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getServerByKey</span><span style="color: #007700">(</span><span style="color: #DD0000">'ip'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>The above example will output
something similar to:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">array(3) {
  [&quot;host&quot;]=&gt;
  string(15) &quot;mem3.domain.com&quot;
  [&quot;port&quot;]=&gt;
  int(11211)
  [&quot;weight&quot;]=&gt;
  int(20)
}
array(3) {
  [&quot;host&quot;]=&gt;
  string(15) &quot;mem2.domain.com&quot;
  [&quot;port&quot;]=&gt;
  int(11211)
  [&quot;weight&quot;]=&gt;
  int(40)
}
array(3) {
  [&quot;host&quot;]=&gt;
  string(15) &quot;mem2.domain.com&quot;
  [&quot;port&quot;]=&gt;
  int(11211)
  [&quot;weight&quot;]=&gt;
  int(40)
}</pre>
</div>
    </div>
   </div>
  </p>
 </div>


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