mysql pdo persistent connection

tyuret used Ask the Experts™
In this link

it says:

"When a persistent connection is requested, PHP checks if there's already an identical persistent connection from earlier remained open. If it exists, it uses it. What meaning of remained open? Persistent connection are links that do not close when the execution of your script ends."

At the end of my every php file I disconnect with making the connection null like this:
$dbpdo = null;

1. So I think I will never have a persistent connection open? Is that right?
2. If so, how will use the idea of improving performance as described at the link?

Thank you
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
In PHP Manual of PDO (, it states that persistent connection only be opened when you specify PDO::ATTR_PERSISTENT => true in open params.

$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass, array(

When you do that, you have persistent connection, regardless of setting $dbh = null, I think.

So all you need to do to open persistent connection is to specify that you WANT to use it.
Most Valuable Expert 2011
Top Expert 2016
If you're using conventional HTTP requests for your web pages, you may find that persistent connections are the opposite of what you want.  Too many web clients can overwhelm the ability of the data base server to make new connections.  I would recommend against persistent connections.  Here is a rhetorical question that will help to illustrate why.  "When your script starts, how does it know whether any of the DB connections are still available or all of the connections have already been used up?"

It's not likely that the overhead of new connections will be noticeable in the larger context of running a PHP script.  You can time this sort of thing using microtime() if you want to verify it for yourself.
Yeah, in general I recommend against persistent connections especially for web applications. As Ray points out, time for a new connection is no longer a meaningful factor and persistent connections stay resident in ways that are somewhat undesirable.

2002 called and it wants its features back.
Most Valuable Expert 2011
Top Expert 2016

@virmaior: Thanks for the best grin of the evening!


Thank you all

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial