Hi,
I'v implemented new_link paramater (as in mysql_connect) for
mysql_pconnect().
Since client_flags were added to those functions in 4.3.x the parameter is
4th in mysql_connect() and 5th in mysql_pconnect().
When new_link is true when connecting to mysql database with
mysql_pconnect() two things happen:
-
you always get unique connection to database (no matter what hostname,
username or password you supplied. When connecting the code will check if
there is an idle connection to server and when found that connection will
be reused. When no connection found, new connection will be created and
registered for future use within same child(/thread?). -
when new_link is true, mysql_pconnect won't waste your connections to
mysql servers like it has been doing up to day. This is achieved by using
mysql_change_user() API call which is available starting from MySQL 3.23.3.
This patch should be great news for people with many virtual servers and
different mysql usernames/password for each user using their service.
With this patch and new_link 'true' connection usage to one server will be
maximum of
[Apache MaxClients conf option]*[different mysql hostname/port combinations]
That means when MaxClients=50 and max_persistent=1
you will get no more that 50 real connection hovering around to same mysql
server.
Without this patch it is (or new_link 'false'):
[Apache MaxClients conf option]*[different mysql hostname/port/username
password combinations]
This means that when MaxClients=50 and max_persistent=1 and have 50 clients
using mysql_pconnect() you could have maximum of 2500!!! connections to one
server. In reality it is not as bad but not good either.
So I think this should patch would be nice to have included in future PHP
releases.
I'm not sure I made good/correct/effective use of PHP/Zend internal
functions. I hope so. If not please point out what's wrong and I'll try to
fix.
Oh, this patch is against PHP4.3.3. Go to ext/mysql dir and 'patch -p1'.
Lenar
Hi,
Next time I'll post patches in the morning after good sleep.
Updated version attached. The original I sent is not useful.
Lenar
Hi,
I'v implemented new_link paramater (as in mysql_connect) for
mysql_pconnect().