<!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="mongo.pooldebug.html">Mongo::poolDebug</a></div> <div class="next" style="text-align: right; float: right;"><a href="mongo.setslaveokay.html">Mongo::setSlaveOkay</a></div> <div class="up"><a href="class.mongo.html">Mongo</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="mongo.setpoolsize" class="refentry"> <div class="refnamediv"> <h1 class="refname">Mongo::setPoolSize</h1> <p class="verinfo">(PECL mongo >=1.2.0)</p><p class="refpurpose"><span class="refname">Mongo::setPoolSize</span> — <span class="dc-title">Set the size for future connection pools.</span></p> </div> <div class="refsect1 description" id="refsect1-mongo.setpoolsize-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>Mongo::setPoolSize</strong></span> ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$size</code></span> )</div> <div class="warning"><strong class="warning">Warning</strong> <p class="simpara">This method has been <em class="emphasis">DEPRECATED</em> as of version 1.2.3. Relying on this feature is highly discouraged. Please use <span class="function"><a href="mongopool.setsize.html" class="function">MongoPool::setSize()</a></span> instead. </p> </div> <p class="para"> Sets the max number of connections new pools will be able to create. </p> </div> <div class="refsect1 parameters" id="refsect1-mongo.setpoolsize-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-mongo.setpoolsize-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns the former value of pool size. </p> </div> <div class="refsect1 examples" id="refsect1-mongo.setpoolsize-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="mongo.setpoolsize.example.basic"> <p><strong>Example #1 <span class="function"><strong>Mongo::setPoolSize()</strong></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">Mongo</span><span style="color: #007700">::</span><span style="color: #0000BB">setPoolSize</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-mongo.setpoolsize-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="mongo.getpoolsize.html" class="function" rel="rdfs-seeAlso">Mongo::getPoolSize()</a> - Get pool size for connection pools</span></li> <li class="member"> <span class="function"><a href="mongo.pooldebug.html" class="function" rel="rdfs-seeAlso">Mongo::poolDebug()</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="mongo.pooldebug.html">Mongo::poolDebug</a></div> <div class="next" style="text-align: right; float: right;"><a href="mongo.setslaveokay.html">Mongo::setSlaveOkay</a></div> <div class="up"><a href="class.mongo.html">Mongo</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>