Dustin Puryear wrote:
> We are running Apache 1.3.20 with PHP 4.0.6/rfc1876-patch built as a
> module. We are using PHP on a load-sharing cluster with n web servers.
> Our cluster supports an application that makes extensive use of mysql
> connections via the PHP mysql_* functions.
> The application was tested on a single web server, and the programmers
> are trying to use persistent connections to increase efficiency.
> First, I want to confirm in my own mind whether this will have any
> real benefit in our situation because we are using a cluster
> environment, correct?
> Second, the programmers are using mysql_connect() and not
> mysql_pconnect(). Does that mean they are in fact not using persistent
> connections? (BTW, we do have persistent connections turned on in
If they are not using the mysql_pconnect functions, then you are not
using persistent connections. The .ini file setting simply allows them
to be used or not - no version I've seen has an option to override to
always use them.
> Finally, the programmers showed me how they see that persistent
> connections are in fact working. On the development server they are
> doing the following:
> On their server the second mysql_query() works!
What is the specific syntax they are using? Is there any chance that
they have opened more than one handle to mysql? The mysql_close() would
only close one, and if there are more than one handles open, only one
will close and others will be free to handle _query() functions.
I'm going to assume they are using mysql_connect() as I can't find
refernce to a mysql_open() function.
The mysql_query function *may* be simply reopening another connection
with the previous information.
From the manual:
mysql_query() sends a query to the currently active database on the
server that's associated with the specified link identifier. If
link_identifier isn't specified, the last opened link is assumed. If no
link is open, the function tries to establish a link as if
mysql_connect() was called with no arguments, and use it.
(They are using Apache
> 1.3.20 as well, but I was told they may have compiled PHP into Apache
> rather than as a module, and I'm not exactly sure of the version, but
> I'm pretty sure it is 4.0.6.) But on the cluster the second
> mysql_query() returns:
> Warning: 1 is not a valid MySQL-Link resource in /some/path/pers.php
> on line 11 could not execute 'select zipcod from zip'
Does that second machine have access to the database? The database may
be only allowing 'localhost' connections or connections from a specific IP.
> Should this be working on our cluster? If not, what do we need to do.
> Can this work?
> Will persistent connections even be effective in a
> cluster environment?
It depends. In the Apache situation, using persistent connections will
cause *each* Apache child to hold a connection open to MySQL. So if you
have 150 apache processes on 3 servers, that's 450 connections the
database server needs to have open for MySQL. ~50k per connection,
that's about 23 meg - should be doable on most machines to start. If
you're running lots of big queries, get loads of RAM. You'll need to
tune mysql to handle more than the default 100 concurrent connections,
and make sure your OS can handle the maximum resources it may require as
Yes, they can be effective. On a fast network with a light loaded
machine using mysql, you often can't tell much of a difference between
pconnect and connect. As the load grows heavier, the pconnects come in
more handy, but at a price of consuming resources you may otherwise need.
If 150 apache processes are serving up HTML and PHP and graphics, one
server may end up holding 150 persistant connections open for a long
time, even though you may only be serving 10-20-30 PHP pages at any one
time. Although the other Apache children are serving graphics/HTML,
they may earlier have run a PHP script with pconnect and will now hold
it open until they die. We tell Apache children to only handle
5000-10000 requests and then specifically die, which should kill the
connection to mysql (some drivers seem to not handle this - freetds had
a problem letting go of handles on the apache exit cycle).
In short, if you're looking to load balance a high load, pconnects can
help, but smart web serving architecture can help too (possibly moreso
> I did read the alt.comp.lang.php FAQ, but it didn't actually address
> this issue.
> Any help or information is appreciated!
Hope that helps some.
Taking the ? out of <?php
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php