Home
Arjen's Journal - Persistent connections in PHP
Moved to http://openquery.com/blog/

Arjen Lentz
Date: 2005-09-06 09:20
Subject: Persistent connections in PHP
Security: Public

mysql_pconnect() in PHP... you don't want it. Really.

If you use Apache 1.3, or 2.0 with PreFork, there will be an instance of PHP inside each Apache process. Each of these will have its own cache of persistent connections.

MySQL actually has a very fast connection setup, so it doesn't save time.
With persistent connections, PHP needs to do some cleanup of a connection, to make sure there are no in-progress transactions, or changed server variables. This is a somewhat inexact science. So much so that Georg Richter has actually completely disabled persistent connections in the PHP 5 mysqli extension.

To disable persistent connections, just use mysql_connect() instead.
You can also, very simply, set mysql.allow_persistent = Off in your php.ini file.

Post A Comment | 2 Comments | Add to Memories | Tell a Friend | Link



midom
User: [info]midom
Date: 2005-09-05 23:27 (UTC)
Subject: thread_cache_size

if you really performance-savvy, you'd have to enable thread_cache_size, so that MySQL would pool free threads for next incoming connections. This way _pconnect() is so dead!

Reply | Thread | Link



Arjen Lentz
User: [info]arjen_lentz
Date: 2005-09-12 19:14 (UTC)
Subject: Re: thread_cache_size

Indeed! Thanks, I forgot to note that in my post in the end ;-)

Reply | Parent | Thread | Link



browse
my journal
links
April 2009
High Performance MySQL (2nd ed.)
summary