[Wolves] PHP/mySQL persistant connection or not?

David Goodwin david at openminds.co.uk
Mon Dec 29 16:02:37 GMT 2003


On Mon, 2003-12-29 at 15:47, Matthew Revell wrote:
> Hello everybody,
> 
> Just a quick question: persistant mySQL connections in PHP, or not?
> 
> I'm working on my little content management project and it's all coming
> along nicely but I still can't decide whether I should be using persistant
> connections to mySQL or not. Any thoughts?


Ideally - Yes. As opening a connection to a database takes time, and
slows stuff down if the site is busy. Persistant connections should
remain open all the time, resulting in a slight overhead, but better
performance. 

The persistant connection should be sharable between seperate requests
in a one-after-the-other manner, speeding things up somewhat. That's the
theory anyway.

However, last time I used PHP, it's persistant connections were lacking
somewhat. As I understand it, each request to a PHP page spawns a new
PHP process. PHP has no shared context (unlike JSP/Java Servlets which
are threaded etc), so it is not possible to share that connection
between multiple seperate requests (because PHP is not threaded...).

So, I think with PHP, the benefit of using a persistant connection may
only be realised if you are opening a connection twice within the same
page request.

Having said all of the above, when I did use persistant connections with
PHP, I noticed that it held 8 (8 being the number of persistant
connections I allowed it to have, I think) connections to the database
open all the time... so I may be wrong - PHP MAY offer true
persistance... but I highly doubt it. 

David.


(I used PHP 4.3 + PostgreSQL for
http://qbab.aber.ac.uk/s_coeli/reference_gel )








More information about the Wolves mailing list