I'm planning to use persistent connection in mysqli by including the following code at the top of every database handler script:
$db = new mysqli('p:localhost', 'db_user', 'db_user_pass', 'db_name');
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
The advantage I see here is that my web application will use only a single connection with the mysql server and hence my app will never show a "Too many connections" error even if there are 10,000 simultaneous users. However, since there will only be a single mysql persistent connection for all the database calls by any script(or different instances of the same script), the SQL queries will queue up instead of getting processed by thousands of parallel mysql connections.
First of all, please correct me if I'm not understanding things correctly. Secondly, if I'm correct, how do I address the issue. On one side is a "Too many connections" problem(if I don't use a persistent connection) and on the other side is a "queueing up of queries" problem(if I use a persistent connection).