I never realize that PHP has no connection pooling to Database. But that is a fact : it just open and closes the connection each time a user hit a page. (There are “persistent connection” but they really are a poor workaround, generally bringing more problems.)
The problem is that traditionnaly, PHP is used for “read-more, write-less” kind of application. Meaning MySQL/MyISAM whithout transaction support. In this case, the connection cost is low and you doesn’t notice it.
eg: every single connection takes up 5MB in NT4 for Oracle 8i 816
This old (2002) PHP’s Creator, Rasmus Lerdorf interview tells why it hasn’t been done :
A pool of connections has to be owned by a single process. Since most people use the Apache Web server, which is a multi-process pre-forking server, there is simply no way that PHP can do this connection pooling …
If/when the common architecture for PHP is a single-process multithreaded Web server, we might consider putting this functionality into PHP itself, but until that day it really doesn’t make much sense. Even Apache 2 is still going to be a multi-process server with each process being able to carry multiple threads. So we could potentially have a pool of connections in each process.
There are solution :
- SQL Relay is a persistent database connection pooling, proxying and load balancing system for Unix and Linux.
- pgpool For PostgreSQL on Linux only. Note : his benchmark isn’t very encouraging.
- Apache DBD API : the mod_dbd module
- ODBC has connection pooling integrated.
- steve roussey
- memcached is a high-performance, distributed memory object caching system, intended for use in speeding up dynamic web applications by alleviating database load.
Final point is : where are the benchmarks !?
How to mesure and monitor the number of connections, the cost of a connection ?