<!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>Set the size for future connection pools.</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mongopool.info.html">MongoPool::info</a></div> <div class="next" style="text-align: right; float: right;"><a href="class.mongo.html">Mongo</a></div> <div class="up"><a href="class.mongopool.html">MongoPool</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="mongopool.setsize" class="refentry"> <div class="refnamediv"> <h1 class="refname">MongoPool::setSize</h1> <p class="verinfo">(PECL mongo >= 1.2.3)</p><p class="refpurpose"><span class="refname">MongoPool::setSize</span> — <span class="dc-title">Set the size for future connection pools.</span></p> </div> <div class="refsect1 description" id="refsect1-mongopool.setsize-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="modifier">static</span> <span class="type">bool</span> <span class="methodname"><strong>MongoPool::setSize</strong></span> ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$size</code></span> )</div> <p class="para rdfs-comment"> Sets the max number of connections new pools will be able to create. </p> </div> <div class="refsect1 parameters" id="refsect1-mongopool.setsize-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"> <em><code class="parameter">size</code></em> </span> <dd> <p class="para"> The max number of connections future pools will be able to create. Negative numbers mean that the pool will spawn an infinite number of connections. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-mongopool.setsize-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns the former value of pool size. </p> </div> <div class="refsect1 changelog" id="refsect1-mongopool.setsize-changelog"> <h3 class="title">Changelog</h3> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>1.2.11</td> <td>Emits <strong><code>E_DEPRECATED</code></strong> when used.</td> </tr> </tbody> </table> </p> </div> <div class="refsect1 examples" id="refsect1-mongopool.setsize-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="mongopool.setpoolsize.example.basic"> <p><strong>Example #1 <span class="function"><a href="mongo.setpoolsize.html" class="function">Mongo::setPoolSize()</a></span> example</strong></p> <div class="example-contents"><p> If you set the pool size to <em>n</em> and then create <em>n</em> connections, attempting to create an <em>n+1</em>st connection will throw a <a href="class.mongoconnectionexception.html" class="classname">MongoConnectionException</a>. </p></div> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /><br /></span><span style="color: #FF8000">// only allow one connection to a server<br /></span><span style="color: #0000BB">MongoPool</span><span style="color: #007700">::</span><span style="color: #0000BB">setSize</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// creates one connection to localhost:27017<br /></span><span style="color: #0000BB">$m1 </span><span style="color: #007700">= new </span><span style="color: #0000BB">Mongo</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">// attempt to create a second connection to localhost:27017<br />// only one connection is allowed, so this will throw an exception<br /></span><span style="color: #0000BB">$m2 </span><span style="color: #007700">= new </span><span style="color: #0000BB">Mongo</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">?></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="cdata"><pre> Fatal error: Uncaught exception 'MongoConnectionException' with message 'no more connections in pool' in /path/to/php/script.php:10 Stack trace: #0 /path/to/php/script.php(10): Mongo->__construct() #1 {main} thrown in /path/to/php/script.php on line 10 </pre></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-mongopool.setsize-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="mongopool.getsize.html" class="function" rel="rdfs-seeAlso">MongoPool::getSize()</a> - Get pool size for connection pools</span></li> <li class="member"> <span class="function"><a href="mongopool.info.html" class="function" rel="rdfs-seeAlso">MongoPool::info()</a> - Returns information about all connection pools.</span></li> <li class="member">The <a href="mongo.connecting.html" class="link">connection</a> documentation.</li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mongopool.info.html">MongoPool::info</a></div> <div class="next" style="text-align: right; float: right;"><a href="class.mongo.html">Mongo</a></div> <div class="up"><a href="class.mongopool.html">MongoPool</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>