What is the best way to ensure I'm writing a scheme to minimize connection count to my MySQL database?
Currently, I have a ubuntu / PHP / apache setup on my server, and I'm using the following code with PDO to ensure a persistent connection:
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass, array(
PDO::ATTR_PERSISTENT => true
));
However, I seem to have 10 or more connections on at all times. I am not sure why this is. Quote from php.net:
Many web applications will benefit from making persistent connections to database servers. Persistent connections are not closed at the end of the script, but are cached and re-used when another script requests a connection using the same credentials. The persistent connection cache allows you to avoid the overhead of establishing a new connection every time a script needs to talk to a database, resulting in a faster web application.
Does this mean I have to write $dbh = null
to "close" and cache the connection?