title: What happens when connections to MongoDB are not closed?
body: <p>I have the following PHP script that basically connects to the MongoDB, writes a document and then closes the connection 19000 times:</p>
  
  <pre><code>&lt;?php
  for($i=0; $i &lt; 19000; $i++) {
      $con = new Mongo("mongodb://localhost:27017");
      $db = $con-&gt;selectDB('test');
  
      $col = $db-&gt;selectCollection('close_wait_test');
      $col-&gt;insert(array('Test' =&gt; 'Value1'));
  
      $con-&gt;close();
  }
  ?&gt;
  </code></pre>
  
  <p>Running this script once works fine, but if I run the script a few seconds later, I get the 'Cannot assign requested address' exception, which is understandable as the server system probably ran out of ports.</p>
  
  <p>If however, I remove $con->close(); I can run that script over and over again without any noticeable strain on the database. I'm assuming this is because the connect to the database is persistent and reuses the same initial connection on the script.</p>
  
  <p>What I'd like to know is if 20k+ different users ran 1 loop of this script at the same time, what would happen to the database? e.g. would the available connections simply run out because each user need creates one connections to the database? or would all those users be using the same initial connection created by the first user?</p>