Source of: /manual/en/function.memcache-setserverparams.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.memcache.inc";
$setup = array (
'home' =>
array (
0 => 'index.php',
1 => 'PHP Manual',
),
'head' =>
array (
0 => 'UTF-8',
1 => 'en',
),
'this' =>
array (
0 => 'function.memcache-setserverparams.php',
1 => 'Memcache::setServerParams',
),
'up' =>
array (
0 => 'ref.memcache.php',
1 => 'Memcache Functions',
),
'prev' =>
array (
0 => 'function.memcache-setcompressthreshold.php',
1 => 'Memcache::setCompressThreshold',
),
'next' =>
array (
0 => 'book.memcached.php',
1 => 'Memcached',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<div id="function.memcache-setserverparams" class="refentry">
<div class="refnamediv">
<h1 class="refname">Memcache::setServerParams</h1>
<p class="verinfo">(PECL memcache >= 2.1.0)</p><p class="refpurpose"><span class="refname">Memcache::setServerParams</span> — <span class="dc-title">Changes server parameters and status at runtime</span></p>
</div>
<a name="function.memcache-setserverparams.description"></a><div class="refsect1 description">
<h3 class="title">Description</h3>
<div class="methodsynopsis dc-description">
<span class="type">bool</span> <span class="methodname"><b>Memcache::setServerParams</b></span>
( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$host</tt></span>
[, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$port</tt></span>
[, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$timeout</tt></span>
[, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$retry_interval</tt></span>
[, <span class="methodparam"><span class="type">bool</span> <tt class="parameter">$status</tt></span>
[, <span class="methodparam"><span class="type"><a href="language.pseudo-types.php#language.types.callback" class="type callback">callback</a></span> <tt class="parameter">$failure_callback</tt></span>
]]]]] )</div>
<p class="para rdfs-comment">
<b>Memcache::setServerParams()</b> changes server parameters at runtime.
You can also use the <b>memcache_set_server_params()</b> function.
</p>
<blockquote><p><b class="note">Note</b>:
This function has been added to Memcache version 2.1.0.
<br />
</p></blockquote>
</div>
<a name="function.memcache-setserverparams.parameters"></a><div class="refsect1 parameters">
<h3 class="title">Parameters</h3>
<p class="para">
</p><dl>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">host</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
Point to the host where memcached is listening for connections.
</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">port</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
Point to the port where memcached is listening for connections.
This parameter is optional and its default value is 11211.
</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">timeout</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
Value in seconds which will be used for connecting to the daemon. Think
twice before changing the default value of 1 second - you can lose all
the advantages of caching if your connection is too slow.
</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">retry_interval</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
Controls how often a failed server will be retried, the default value
is 15 seconds. Setting this parameter to -1 disables automatic retry.
Neither this nor the <i><tt class="parameter">persistent</tt></i>
parameter has any
effect when the extension is loaded dynamically via <a href="function.dl.php" class="function">dl()</a>.
</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">status</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
Controls if the server should be flagged as online. Setting this parameter
to <b><tt class="constant">FALSE</tt></b> and <i><tt class="parameter">retry_interval</tt></i>
to -1 allows a failed
server to be kept in the pool so as not to affect the key distribution
algoritm. Requests for this server will then failover or fail immediately
depending on the <i><tt class="parameter">memcache.allow_failover</tt></i>
setting.
Default to <b><tt class="constant">TRUE</tt></b>, meaning the server should be considered online.
</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">failure_callback</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
Allows the user to specify a callback function to run upon encountering an
error. The callback is run before failover is attempted. The function takes
two parameters, the hostname and port of the failed server.
</p>
</dd>
</dl>
<p>
</p>
</div>
<a name="function.memcache-setserverparams.returnvalues"></a><div class="refsect1 returnvalues">
<h3 class="title">Return Values</h3>
<p class="para">
Returns <b><tt class="constant">TRUE</tt></b> on success or <b><tt class="constant">FALSE</tt></b> on failure.
</p>
</div>
<a name="function.memcache-setserverparams.examples"></a><div class="refsect1 examples">
<h3 class="title">Examples</h3>
<p class="para">
</p><div class="example">
<p><b>Example #1 <b>Memcache::setServerParams()</b> example</b></p>
<div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB"><?php<br /><br /></span><span style="color: #007700">function </span><span style="color: #0000BB">_callback_memcache_failure</span><span style="color: #007700">(</span><span style="color: #0000BB">$host</span><span style="color: #007700">, </span><span style="color: #0000BB">$port</span><span style="color: #007700">) {<br /> print </span><span style="color: #DD0000">"memcache '</span><span style="color: #0000BB">$host</span><span style="color: #DD0000">:</span><span style="color: #0000BB">$port</span><span style="color: #DD0000">' failed"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">/* OO API */<br /><br /></span><span style="color: #0000BB">$memcache </span><span style="color: #007700">= new </span><span style="color: #0000BB">Memcache</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Add the server in offline mode<br /></span><span style="color: #0000BB">$memcache</span><span style="color: #007700">-></span><span style="color: #0000BB">addServer</span><span style="color: #007700">(</span><span style="color: #DD0000">'memcache_host'</span><span style="color: #007700">, </span><span style="color: #0000BB">11211</span><span style="color: #007700">, </span><span style="color: #0000BB">false</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">, -</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">false</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Bring the server back online<br /></span><span style="color: #0000BB">$memcache</span><span style="color: #007700">-></span><span style="color: #0000BB">setServerParams</span><span style="color: #007700">(</span><span style="color: #DD0000">'memcache_host'</span><span style="color: #007700">, </span><span style="color: #0000BB">11211</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">15</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">, </span><span style="color: #DD0000">'_callback_memcache_failure'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* procedural API */<br /><br /></span><span style="color: #0000BB">$memcache_obj </span><span style="color: #007700">= </span><span style="color: #0000BB">memcache_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'memcache_host'</span><span style="color: #007700">, </span><span style="color: #0000BB">11211</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">memcache_set_server_params</span><span style="color: #007700">(</span><span style="color: #0000BB">$memcache_obj</span><span style="color: #007700">, </span><span style="color: #DD0000">'memcache_host'</span><span style="color: #007700">, </span><span style="color: #0000BB">11211</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">15</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">, </span><span style="color: #DD0000">'_callback_memcache_failure'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?></span>
</span>
</code></div>
</div>
</div><p>
</p>
</div>
<a name="function.memcache-setserverparams.seealso"></a><div class="refsect1 seealso">
<h3 class="title">See Also</h3>
<p class="para">
</p><ul class="simplelist">
<li class="member"><a href="function.memcache-addserver.php" class="function" rel="rdfs-seeAlso">Memcache::addServer()</a> - Add a memcached server to connection pool</li>
<li class="member"><a href="function.memcache-getserverstatus.php" class="function" rel="rdfs-seeAlso">Memcache::getServerStatus()</a> - Returns server status</li>
</ul><p>
</p>
</div>
</div><?php manual_footer(); ?>