📄 function.memcache-addserver.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Add a memcached server to connection pool</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.memcache-add.html">Memcache::add</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.memcache-close.html">Memcache::close</a></div> <div class="up"><a href="ref.memcache.html">Memcache Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.memcache-addserver" class="refentry"> <div class="refnamediv"> <h1 class="refname">Memcache::addServer</h1> <p class="verinfo">(No version information available, might be only in CVS)</p><p class="refpurpose"><span class="refname">Memcache::addServer</span> — <span class="dc-title">Add a memcached server to connection pool</span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><b><b>Memcache::addServer</b></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">bool</span> <tt class="parameter">$persistent</tt></span> [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$weight</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.html#language.types.callback" class="type callback">callback</a></span> <tt class="parameter">$failure_callback</tt></span> ]]]]]]] )</div> <p class="para rdfs-comment"> <b>Memcache::addServer()</b> adds a server to the connection pool. The connection, which was opened using <b>Memcache::addServer()</b> will be automatically closed at the end of script execution, you can also close it manually with <a href="function.memcache-close.html" class="function">Memcache::close()</a>. You can also use the <b>memcache_add_server()</b> function. </p> <p class="para"> When using this method (as opposed to <a href="function.memcache-connect.html" class="function">Memcache::connect()</a> and <a href="function.memcache-pconnect.html" class="function">Memcache::pconnect()</a>) the network connection is not established until actually needed. Thus there is no overhead in adding a large number of servers to the pool, even though they might not all be used. </p> <p class="para"> Failover may occur at any stage in any of the methods, as long as other servers are available the request the user won't notice. Any kind of socket or Memcached server level errors (except out-of-memory) may trigger the failover. Normal client errors such as adding an existing key will not trigger a failover. </p> <blockquote><p><b class="note">Note</b>: This function has been added to Memcache version 2.0.0. <br /> </p></blockquote> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">host</tt></i></span> <dd> <p class="para"> Point to the host where memcached is listening for connections. This parameter may also specify other transports like <i>unix:///path/to/memcached.sock</i> to use UNIX domain sockets, in this case <i><tt class="parameter">port</tt></i> must also be set to <i>0</i>. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">port</tt></i></span> <dd> <p class="para"> Point to the port where memcached is listening for connections. This parameter is optional and its default value is 11211. Set this parameter to <i>0</i> when using UNIX domain sockets. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">persistent</tt></i></span> <dd> <p class="para"> Controls the use of a persistent connection. Default to <b><tt>TRUE</tt></b>. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">weight</tt></i></span> <dd> <p class="para"> Number of buckets to create for this server which in turn control its probability of it being selected. The probability is relative to the total weight of all servers. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">timeout</tt></i></span> <dd> <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> <dt> <span class="term"><i><tt class="parameter">retry_interval</tt></i></span> <dd> <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.html" class="function">dl()</a>. </p> <p class="para"> Each failed connection struct has its own timeout and before it has expired the struct will be skipped when selecting backends to serve a request. Once expired the connection will be successfully reconnected or marked as failed for another <i><tt class="parameter">retry_interval</tt></i> seconds. The typical effect is that each web server child will retry the connection about every <i><tt class="parameter">retry_interval</tt></i> seconds when serving a page. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">status</tt></i></span> <dd> <p class="para"> Controls if the server should be flagged as online. Setting this parameter to <b><tt>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 immediatly depending on the <i><tt class="parameter">memcache.allow_failover</tt></i> setting. Default to <b><tt>TRUE</tt></b>, meaning the server should be considered online. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">failure_callback</tt></i></span> <dd> <p class="para"> Allows the user to specify a callback function to run upon encountering an error. The callback is run before failover is attemped. The function takes two parameters, the hostname and port of the failed server. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <b><tt>TRUE</tt></b> on success or <b><tt>FALSE</tt></b> on failure. </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 <b>Memcache::addServer()</b> example</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<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 /></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">);<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_host2'</span><span style="color: #007700">, </span><span style="color: #0000BB">11211</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_add_server</span><span style="color: #007700">(</span><span style="color: #0000BB">$memcache_obj</span><span style="color: #007700">, </span><span style="color: #DD0000">'memcache_host2'</span><span style="color: #007700">, </span><span style="color: #0000BB">11211</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </div> <div class="refsect1 seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="function.memcache-connect.html" class="function" rel="rdfs-seeAlso">Memcache::connect()</a></li> <li class="member"><a href="function.memcache-pconnect.html" class="function" rel="rdfs-seeAlso">Memcache::pconnect()</a></li> <li class="member"><a href="function.memcache-close.html" class="function" rel="rdfs-seeAlso">Memcache::close()</a></li> <li class="member"><a href="function.memcache-setserverparams.html" class="function" rel="rdfs-seeAlso">Memcache::setServerParams()</a></li> <li class="member"><a href="function.memcache-getserverstatus.html" class="function" rel="rdfs-seeAlso">Memcache::getServerStatus()</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.memcache-add.html">Memcache::add</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.memcache-close.html">Memcache::close</a></div> <div class="up"><a href="ref.memcache.html">Memcache Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -