views:

258

answers:

2

I had never heard of persistent connections before, and I don't understand the advantages. I run a PHP/MySQL based internet website, it receives tens of thousands of page views per day. In my header file on each of these pages I have just used mysql_connect() and I haven't bothered with terminating the connection in the footer file.

In my case are there any advantages of using mysql_pconnect() ?

+4  A: 

Using a persistent connection leaves the connection open after the script has finished executing. Opening and closing connections over and over causes overhead, while small, that will eventually mount up as the number of requests go up.

However, if you read the manual page for mysql_pconnect it states:

  • If PHP and MySQL are on the same server or local network, the connection time may be negligible, in which case there is no advantage to persistent connections.

If this is the case it may not be worth the trouble changing your code.

You can find more detailed information on persistent connections at the same site as above.

Peter Spain
A: 

Check out this URL:

http://us3.php.net/manual/en/function.mysql-pconnect.php

Basically mysql_pconnect() tries to find a persistent connection already open with the credentials that you've specified. If it doesn't find one it makes a new one. It also doesn't close the connection after a statement is executed

So really in your case you may not notice a difference but in reality you should probably be using mysql_pconnect().

Wade