MongoDB Database Connection in PHP -
i using following code connect mongodb php. here extension info localhost, , same on beta , prod.
i using following code connect database.
class webapi { private $mongoclient; function __construct() { $mongoclient = new mongodb\client("mongodb://database.local:27017"); if(!$mongoclient){ //todo: inform status site 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, use connection pooling. suspect mongodb has one, not sure. googled it, nothing handy comes new mongodb 1.1.x version.
is more better way this?
update
as said luiz eduardo de christo here, extending question more relevant info.
in case connection pooling not relevant, how deal huge volume of connections? how ram each connection take, provided, managed use 1 connection every http request , manage transactions using 1 connection, have server 8gb ram, hexacore xeon e5 @ 3.1 ghz on centos or ubuntu, running mongod
alone without other server apache, how maximum connections can make? how many concurrent users server able handle? there way optimise on mongodb 3.2?
ps: no information able find database optimisation respect server configuration.
your code looks fine. regarding pooling:
according php manual:
this section no longer relevant of 1.3.0 release of driver , serves historical information on how pooling used work. "the latest versions of driver have no concept of pooling anymore , maintain 1 connection per process, each connection type (replicaset/standalone/mongos), each credentials combination."
http://php.net/manual/pt_br/mongo.connecting.pools.php
best regards, eduardo.
Comments
Post a Comment