Connection pooling is something which multithreaded programs can use. PHP usually runs in a multi-process scenario, which is not compatible with connection pooling.
The only thing you have similar to connection pooling, is persistent connections. These however, need to be used carefully as it's easy to screw things up with them. The most common problems are:
- Too many connections - if your server is serving more than one application, or your application is using more than one database, that number will be multiplied by the number of processes. Use just ONE connection across the entire app, and don't run any other apps on the same server (or rather, use persistent connections on just one of them).
You should definitely check MaxClients (e.g. if using Apache), and ensure that it's not too high. More than 50 is probably too many. Remember that this is the maximum number of PHP processes you can have, with one persistent connection each.
- Connection state hanging over from previous requests
PHP doesn't make any attempt to reset the state of a persistent connection - therefore it's vital that you don't do anything stateful. This pretty much includes transactions.
Or rather, you COULD do something stateful, but be very careful that you reset the connection to a sane state when your page finishes (Even in the case of an error) - register_shutdown_function could help here, perhaps doing a ROLLBACK.
Any parameters you set (e.g. SET NAMES utf8) should be set consistently after every connection is created. Otherwise, you might run into trouble using old persistent connections.
If you're using a local MySQL database, I wouldn't bother using persistent connections, as connecting locally over a Unix socket (Or perhaps NT named pipe) is very fast.
On the other hand, something like an Oracle server located in Zimbabwe over a VPN has a longer connection time.
If you're running into serious connection performance problems, consider using an intermediate proxying server which does its own connection pooling, if that is possible.
Mark