简体   繁体   中英

mongodb and php: connection pooling

I'm using the native driver in PHP to connect to a mongo DB.

I don't understand the concept of connection pooling: is this like a 'pool' of connections, and when a user opens the website, a connection is pulled from this pool and used?

But what if you have multiple pages with some code that uses a mongoDB? Will the system pull a new connection from the pool every time the user changes the page?

In general: how can I manage this 'connection pool' (or is it managed automatically) when there are a lot of simultaneous connections?

I don't understand the concept of connection pooling: is this like a 'pool' of connections, and when a user opens the website, a connection is pulled from this pool and used?

Yes, that's exactly what it is.

But what if you have multiple pages with some code that uses a mongoDB? Will the system pull a new connection from the pool every time the user changes the page?

Yes. The connection is taken from the pool when required (a user loads a page), and then returned to the pool when the script ends. It is persistent by default (set via the mongo.allow_persistent php.ini setting) and automatically handled by the driver.

In general: how can I manage this 'connection pool' (or is it managed automatically) when there are a lot of simultaneous connections?

Connection pools are mostly managed automatically. You have some level of control using the MongoPool class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM