title: MongoDB PHP Uncaught MongoDB\Driver\Exception\ConnectionTimeoutException: No suitable servers found
body: <p>I'm stuck with this strange problem.</p>
  
  <pre><code>&lt;?php
  require_once __DIR__ . "/vendor/autoload.php";
  
  ini_set('display_errors', 1);
  ini_set('display_startup_errors', 1);
  error_reporting(E_ALL);
  
  // connect to mongodb
  $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
  
  $command = new MongoDB\Driver\Command(array("ping" =&gt; 1));
  $result = $manager-&gt;executeCommand("test", $command);
  
  var_dump($result, $result-&gt;toArray());
  ?&gt;
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>Fatal error: Uncaught MongoDB\Driver\Exception\ConnectionTimeoutException: No suitable servers found (`serverSelectionTryOnce` set): [connection refused calling ismaster on 'localhost:27017'] in /var/www/html/mongo.php:11 Stack trace: #0 /var/www/html/mongo.php(11): MongoDB\Driver\Manager-&gt;executeCommand('test', Object(MongoDB\Driver\Command)) #1 {main} thrown in /var/www/html/mongo.php on line 11
  </code></pre>
  
  <p>Why it is strange? Well, I already tried searching around the internet about this problem, people always say the same thing:</p>
  
  <ol>
  <li>The MongoDB server is offline</li>
  <li>The MongoDB server data is corrupted</li>
  </ol>
  
  <p>Well...</p>
  
  <p>It isn't offline, my Java applications (and "mongo") can connect to the MongoDB server just fine and can interact with the database without throwing the ConnectionTimeoutException.</p>
  
  <pre><code>try {
      mongoClient = new MongoClient( "localhost" );
  } catch (UnknownHostException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  }
  </code></pre>
  
  <p>It isn't corrupted, because if it was corrupted, I won't be able to connect it via Java (right?)</p>
  
  <p>I already tried connecting to 127.0.0.1 and localhost, same issue.</p>
  
  <p>I already tried restarting httpd and mongod, same issue.</p>
  
  <p>I already tried binding the MongoDB server to 0.0.0.0 instead of 127.0.0.1, same issue.</p>
  
  <p>Yes, MongoDB drivers are installed, they are active in PHP Info.</p>
  
  <p>MongoDB PHP version: 1.2.1</p>
  
  <p>MongoDB shell version: 3.2.10 (now updated to 3.4.0)</p>
  
  <p>PHP version: 7.0.13</p>