--- Nicole <[EMAIL PROTECTED]> wrote:
>  I don't see a MaxConnections in Apache conf, or maybe I overlooked
> it. I do see:
> 
> MaxClients 150

Maximum connections is the MySQL configuration option. MaxClients is the Apache
directive I mentioned.

Ultimately, all you have to do to use persistent connections is make sure that
you allow more connections to MySQL than could possibly be used by all
applications that use it. In an environment where you only have Apache (PHP)
accessing the database, this means you want MySQL's maximum connections set
higher than Apache's maximum number of clients. I usually leave at least one
extra MySQL connection for myself (in case a bug in my application causes all
connections to be hung).

Other than that, you just use mysql_pconnect to connect, and you don't use
mysql_close (otherwise you'll be making things worse).

One big caveat to using persistent connections is that if you have problems in
your scripts or with the stability of your applications, using persistent
connections can potentially make things worse. If your script hangs due to an
infinite loop or some other programming error, you may cause a MySQL lock to
remain that ties up other Apache child processes indefinitely. I'm sure there
are a lot of things like this that I can't even think of at the moment. But, if
things are working well, persistent connections can be a big help to a stressed
database server.

> I did read -- in various places -- that it was better to use
> connect, including PHP. Because php and mysql are fast to open a
> regular connection, using connect may ultimately be better. That's
> just what I read.

Where? If you found it in the PHP Manual, then it may need to be corrected
(depending on exactly what is stated). What the manual does state (when
speaking about persistent database connections in general) is that persistent
connections are helpful if the cost of establishing a connection is high. This
is just to be safe. Because managing the pool of connections and performing the
lookup does take some finite amount of time, it is possible that establishing a
connection to a database could be faster than this overhead. With MySQL, I have
never seen this to be the case, and you won't see this statement made here:

http://www.php.net/mysql_pconnect

> I found this bit:
> http://us2.php.net/manual/en/features.persistent-connections.php
> 
> So really, I am confused on this matter. I believe it boils down to
> configuration issues betweeen MySQL's conf and Apache's conf files.
> Maybe even in php.ini. I can't seem to find a correct article on how
> to fix these things. What I read in forums I become leary of,
> thinking the person may be incorrect. So I like to stick to
> documentation. But I can't seem to find enough.

Don't rule our programming errors. If you want more specific help, you might
try to give us some statistics, such as how quickly MySQL's connections are
filled up and whether it is at a faster rate than Apache seems to be spawning
new child processes. Any sort of data would help us to make a guess. If
possible, you might want to load test a very simple script that performs a
simple query and see what the characteristics are. Can you be certain that all
of your PHP scripts are terminating properly?

Also, documentation is just written by regular people. They can be wrong. I've
contributed to the PHP Manual, and I've been wrong plenty of times (hopefully
not in the manual, of course).

Hope that helps.

Chris

=====
HTTP Developer's Handbook
     http://shiflett.org/books/http-developers-handbook
RAMP Training Courses
     http://www.nyphp.org/ramp
My Blog
     http://shiflett.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to