I am using clearDB
database for my windows azure
based php
application. I am getting intermittent error on mysql
connections. Currently we have nearly 2000 online customers. And we have 30 connections from database.
How can I scale the website and overcome this situation?
I am taking care of closing connection most of the times. For now I have prevented server errors by this:
try {
$this->_conn = $this->dbh = new PDO('mysql:host=' . DB_SERVER . ';dbname='. DB_NAME, DB_USER, DB_PASS);
$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
die("Couldn't connect to database. Please try again!");
}
So, if there is no connections left, then it'll show appropriate message. But, It's not feasible for customer facing websites. How can I solve this problem?
EDIT
How can I analyse this data:
Array
(
[0] => Array
(
[Variable_name] => Connections
[Value] => 505369
)
[1] => Array
(
[Variable_name] => Threads_cached
[Value] => 54
)
[2] => Array
(
[Variable_name] => Threads_connected
[Value] => 65
)
[3] => Array
(
[Variable_name] => Threads_created
[Value] => 1038
)
[4] => Array
(
[Variable_name] => Threads_running
[Value] => 4
)
)
I got above result after: SHOW STATUS WHERE variable_name LIKE 'Threads_%' OR variable_name = 'Connections'