Alok
Alok

Reputation: 184

How to handle concurrent DB connections by multiple users using PDO in PHP5

I want to use PDO in my application. However I am confused regarding the use of PDO here. Because my application access target will be multiple users. Lets say 100 users in simultaneously . So, as I read about PDO it will create 100 db connections to access. This can create a problem as it will limit on concurrent connections allowed by Server. And new users will get connection error.

How can I use PDO such a way that it handles the concurrent connections and does not overhead?

Upvotes: 0

Views: 1421

Answers (2)

Your Common Sense
Your Common Sense

Reputation: 157896

100 concurrent users is not that impressive number though. Taken average user makes a click once a minute, we have 100 connects for 60 seconds, which makes 1.5 connects / second.
A sanely written app should perform no longer 0,1 sec. means 10 connections could be fit in one second. and we have 1.5.

Yes, it can peak sometimes, but anyway, number of allowed connections would be the last thing I would think of. Most likely your database will be killed far earlier than limit reached - due to improper indexing and architecture.

Upvotes: 2

mleko
mleko

Reputation: 12233

You can use persistent connections. Instead of closing and reopening, PDO will return you unused connections. This should reduce overhead and also amount of opened connections.

http://www.php.net/manual/en/pdo.connections.php

Upvotes: 0

Related Questions