Are there thread pools in PHP?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ivj
Forum Commoner
Posts: 31
Joined: Sat Mar 05, 2005 3:07 am

Are there thread pools in PHP?

Post by ivj »

I'm learning PHP and reading PHP-MySQL tutorials I notice that you make a new connection to the database every time.

Coming from Java that sounds terribly inefficient. In 99% of DB applications I'd have a thread pool constantly running a few idle connections. Doesn't PHP do that sort of thing somehow? Googling didn't help much, so what do you pros say?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I don't think so. I am looking into connection pooling tools right now for an app I am working on.
wyrmmage
Forum Commoner
Posts: 56
Joined: Sat Oct 28, 2006 12:43 pm
Location: boise, ID

Post by wyrmmage »

Not that I have heard of, however there is such a thing as a "persistent connection", but it's not used much.
-wyrmmage
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Are there thread pools in PHP?

Post by onion2k »

ivj wrote:I'm learning PHP and reading PHP-MySQL tutorials I notice that you make a new connection to the database every time.

Coming from Java that sounds terribly inefficient. In 99% of DB applications I'd have a thread pool constantly running a few idle connections. Doesn't PHP do that sort of thing somehow? Googling didn't help much, so what do you pros say?
mysql_pconnect() will check for a pooled (persistant) connection that will be reused if there's one free, or creates a new one if there isn't a spare. You need to be careful when you're using them because you can easily sink MySQL. Read this: http://uk2.php.net/manual/en/features.p ... ctions.php
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

So far in my quest for a connection pooler, I have found one that seems like it might help. It does have its issues, but it also handles pooling. It is SQL Relay.
Post Reply