This was originally sent to the httpd-users mailing list, I'm moving it to
the php-general list to bring it on-topic and because I think it's something
worth sharing. I'm also hoping I actually remembered the address for the
php-general list since I typically post there via the newsgroup.

On Thursday, May 30, 2002 at 7:34 AM, "Peter" <[EMAIL PROTECTED]>

> I am designing a web site which has a number of  pages. One of these
> provides the facility for the user to log onto a mysql database.  Other
> pages allow the user to query and update different tables in the database.
> I used the mysql_pconnect function in the login page and assumed that the
> connection would automatically be available to all other pages in the site
> as hey are invoked, but find that I have to include it in every page that
> access the data base.

mysql_pconnect creates a persistent database connection that survives across
multiple page loads, however, the connection is NOT always available to all
other pages. Specifically:
1. You still must call mysql_pconnect in each page that accesses the db.
What mysql_pconnect does is avoid the overhead of reconnecting -- but you'll
need to call it again on each page to get the connection handle. Read more

2. If you are running your webserver in multiple processes (99% of the time
this is true with Apache, which you are using) and the same user happens to
be served by multiple processes, each process will require its own
connection to the server -- which will be made the first time that process
calls mysql_pconnect. Since your particular setup has a user logging into a
mysql database (presumably with their own account instead of one shared db
account that takes care of db management via your code), this means you can
have a theoretical maximum of users * processes connections to your
database. Make sure MySQL is configured to allow that many connections. (20
apache processes and 10 users is 200 connections that stick around a long adds up real fast!). If the ability to raise the connection limit
isn't available, you may want to use mysql_connect instead -- slightly
slower, but you won't have to worry about unused connections lingering.
(It's still possible to hit the limit, though, just not as likely.)

-- Daniel Grace

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to