My application will be hosted in a shared hosting provider with a limit of 25 Mysql concurrent connections. Below is my code for connecting to DB
function dbConnect() {
$dbHost = 'localhost';
$dbUser = 'user';
$dbPass = 'pass';
$dbName = 'dbase';
mysql_connect($dbHost, $dbUser, $dbPass)or die(mysql_error());
mysql_select_db($dbName) or die(mysql_error());
}
My application is more on database query. The home page alone has atleast 20 mysq_query in it. The way I code my home page is like below
include 'config.php';
dbConnect();
query1 … //to get initial variables
process variables that result in multiple query
query2… // process result
query3…// process result
and so on up to….
query 20…// process result
I cant minimize the query anymore coz most of the query is prerequisite of the other query. I am expecting of at least 1000 users daily, and the possibility of 50% of the users will connect on the same time or at lest seconds apart.
- On the design of connecting to DB will I easily reach the connection limit set?
- Is php closing the connection right after the query, meaning it closes after the first query, then open on the second and closes again right after, and so on and son, even if I’m not closing the connection myself
- Is my assumption correct that the above scenario automatically consumed 20 concurrent connections?
Thanks in advance.
For what it’s worth, some answers to questions 2. and 3. of genpet’s original post:
PHP closes your connection to MySQL if and only if (assuming it wasn’t openned with
mysql_pconnect()):mysql_close()Therefore, if you send 20 queries during the same script, you only consume 1 connection
One thought just comes to my mind. Consider this pattern:
*_pconnect()*_close()This way, I believe one could work around the low concurrent connections limit (even though I agree with people advising your hosting plan may be inappropriate to fulfill your needs)
This is theory, though, I haven’t tried that in the real.