PHP MongoDB context options


PHP can interact with MongoDB database through database extensions. For older versions of PHP, mongo driver can be installed from PECL. This has now been replaced by mongodb driver. Both drivers can be installed using precompiled binaries for Linux/Windows/MacOS operating systems. Alternately, manual installation can be done from source tarball available on github. In either case, mongo or mongodb extension should be enabled in php.ini settings.

The PHP MongoDB extension provides Stream Context Support using the mongodb context. Relevent context options are as follows


log_cmd_insert ( array $server , array $document , array $writeOptions , array $protocolOptions )

This is a callable function, used by the log_cmd_insert context option, when inserting a document

log_cmd_delete ( array $server , array $writeOptions , array $deleteOptions , array $protocolOptions )

This is a callback function, used by the log_cmd_delete context option, when deleteing a document

log_cmd_update ( array $server , array $writeOptions , array $updateOptions , array $protocolOptions )

This function is used by the log_cmd_update context option, when updateing a document

log_write_batch ( array $server , array $writeOptions , array $batch , array $protocolOptions )

This function is used by the log_write_batch context option, when executing a batch operation.

log_reply ( array $server , array $messageHeaders , array $operationHeaders )

This callback function is used When Reading the MongoDB reply

log_getmore ( array $server , array $info )

when executing a GET_MORE operation, this callable function is used by the log_getmore context option

log_killcursor ( array $server , array $info )

Callback When Executing KILLCURSOR operations

$server array contains basic information of following parameters

hash− server hash, example: localhost:27017;-;X;56052

type − Node type (primary/secondary/mongos/arbiter) − 2

max_bson_size − The maximum BSON Size over the wire this node accepts − 16777216

max_message_size − The maximum Message Size over the wire this node accepts − 48000000

request_id − The request identifier for this message − 42