Connection pooling with PHP : a growing problem ?

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.

But as PHP is more widely used (IBM, Oracle), people begin to connect to, for example, Oracle wich is another beast :

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 ?

One Response to Connection pooling with PHP : a growing problem ?

  1. Antibush says:

    Bush goes ballistic about other countries being evil and dangerous, because they have weapons of mass destruction. But, he insists on building up even a more deadly supply of nuclear arms right here in the US. What do you think? How does that work in a democracy again? How does being more threatening make us more likeable?Isn’t the country with
    the most weapons the biggest threat to the rest of the world? When one country is the biggest threat to the rest of the world, isn’t that likely to be the most hated country?
    Are we safer today than we were before?
    We have lost friends and influenced no one. No wonder most of the world thinks we suck. Thanks to what george bush has done to our country during the past three years, we do!

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: