0

Trying to check connection with mongodb server using php driver manager! I googled many times to get the method like $DriverManager->checkConnection() or any property like $DBmanager->connected!

Current output from php var_dump MongoDB\Driver\Manager

object(MongoDB\Driver\Manager)#10 (2) {
  ["uri"]=>
  string(24) "mongodb://127.0.0.1:27017"
  ["cluster"]=>
  array(0) {
  }
}

I checked by starting the database server and then without running the server! There is no difference between var_dump results!

Any help?

2
  • Why do you need it? just execute any command, and check for errors. Commented May 19, 2017 at 8:06
  • Wanna make sure my program have enough resources to run on web! Commented May 20, 2017 at 4:55

1 Answer 1

1

The MongoDB\Driver\Manager is the main entry point to the extension. It is responsible for maintaining connections to MongoDB (be it standalone server, replica set, or sharded cluster).

No connection to MongoDB is made upon instantiating the Manager. This means the MongoDB\Driver\Manager can always be constructed, even though one or more MongoDB servers are down.

Any write or query can throw connection exceptions as connections are created lazily. A MongoDB server may also become unavailable during the life time of the script. It is therefore important that all actions on the Manager to be wrapped in try/catch statements.

final MongoDB\Driver\Manager {
/* Methods */
final public __construct ([ string $uri = "mongodb://127.0.0.1/" [, array $uriOptions = [] [, array $driverOptions = [] ]]] )
final public MongoDB\Driver\WriteResult executeBulkWrite ( string $namespace , MongoDB\Driver\BulkWrite $bulk [, MongoDB\Driver\WriteConcern $writeConcern ] )
final public MongoDB\Driver\Cursor executeCommand ( string $db , MongoDB\Driver\Command $command [, MongoDB\Driver\ReadPreference $readPreference ] )
final public MongoDB\Driver\Cursor executeQuery ( string $namespace , MongoDB\Driver\Query $query [, MongoDB\Driver\ReadPreference $readPreference ] )
final public MongoDB\Driver\ReadConcern getReadConcern ( void )
final public MongoDB\Driver\ReadPreference getReadPreference ( void )
final public array getServers ( void )
final public MongoDB\Driver\WriteConcern getWriteConcern ( void )
final public MongoDB\Driver\Server selectServer ( MongoDB\Driver\ReadPreference $readPreference )
}

var_dump()ing a MongoDB\Driver\Manager will print out various details about the manager that are otherwise not normally exposed. This can be useful to debug how the driver views your MongoDB setup, and which options are used.

<?php $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
var_dump($manager); ?>

Reference : Link

Sign up to request clarification or add additional context in comments.

1 Comment

Hello S N Tiwari ! [ Can you answer?](stackoverflow.com/questions/44282664/…)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.