I am using the following code to connect to my mongoDB from PHP. Here is my extension info from my localhost, and the same is on beta and prod.
I am using the following code to connect to database.
class WebAPI {
private $mongoClient;
function __construct() {
$mongoClient = new MongoDB\Client("mongodb://database.local:27017");
if(!$mongoClient){
//TODO: Inform status site about failure
http_response_code(500);
die();
}
$statsDB = $mongoClient->stats; //selects database stats
$pageViewsCollection = $statsDB->pageviews;
$result = $pageViewsCollection->insertOne(PageViewInsights::getInfo());
var_dump($result->getInsertedId());
}
}
In SQL databases, we use connection pooling. I suspect mongodb also has one, I am not sure. I googled it, but nothing handy comes up for this new mongodb 1.1.x version.
Is the a more better way to do this?
UPDATE
As said by Luiz Eduardo de Christo here, I am extending the question for the more relevant info.
In case connection pooling is not relevant, how to deal with huge volume of connections? How much RAM each connection will take, provided, I managed to use only one connection for every HTTP request and manage all transactions using that one connection, say I have a server with 8GB RAM, Hexacore Xeon E5 @ 3.1 GHz on CentOS or Ubuntu, running mongod
alone without any other server like apache, how much maximum connections can I make? How many concurrent users my server is able to handle? Is there a way to optimise this on MongoDB 3.2?
PS: No information I am able to find about database optimisation with respect to server configuration.