mysql_pconnect() vs. mysql_connect

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Swede78
Forum Contributor
Posts: 198
Joined: Wed Mar 12, 2003 12:52 pm
Location: IL

mysql_pconnect() vs. mysql_connect

Post by Swede78 »

The more opinions I read on this issue, the more confused I get. I have a book that suggests using pconnect because it's faster and creates less stress on the mysql server than regular connect. I've read in other places, that the regular connect is better because it creates less simultaneous connections that aren't always necessary and that the speed difference is so small that it doesn't matter.

I've been using pconnect as a standard (because of Dreamweaver) and haven't seen a problem until just recently. I upgraded mysql to the latest version, and I believe I read somewhere in the mysql installation notes that they suggest not using pconnect. Immediately after the upgrade, there were some connection errors, but I believe that was because of old sessions trying to connect. Those errors dissolved after the 1st day.

Yesterday, I had some "Too Many Connections" errors. I'm not sure why this happened.

So, I'm just looking for reasons to use one or the other. My website averages about 15-30 simultaneous visitors most of the day. I peak at about 60. About 95% of my site pages uses a mysql connection. Probably 99.99% of the traffic is on a page with mysql.

All suggestions and opinions are appreciated. I said in the first sentence, that the more opinions I get, the more confusion it causes. But, so far that's because I'm getting an equal amount of opposing views. I'm hoping I'll get an overwhelming majority of which is better.

Thanks in advance!
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

pconnect is something for as far as i see, kinda old

the only time that i might use pconnect is when using mssql
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

If the mysql server is on the same server as the webserver then using pconnect can actually cause more of an overhead than just a connect.
Plus pconnect 'ties' up connections that could be used by other processes. I'd stick with a connect unless you're using distributed databases or a database on another server etc..
Swede78
Forum Contributor
Posts: 198
Joined: Wed Mar 12, 2003 12:52 pm
Location: IL

Post by Swede78 »

Thanks, I've switched to regular connect, and all seems well.
Post Reply