Re: mysql_pconnect / persistent database conections

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ben Edwards wrote:
> Been meaning to investigate persistent database connections for a
> while.  Coming from a rdbms background (oracle with a bit of whatcom
> sqlanywhare) I have always felt that the overhead of opening a
> connection at the beginning of each page was a little resource
> intensive.

Pretty much is the biggest time sink on most small/medium web-sites.

> Anyway, I found mysql_pconnect and this sounds like just the ticket.
> Seems that I can just change my connect method from mysql_connect to
> mysql_pconnect and it will just work.

Yes, but...

> I do have a couple of questions.  Firstly what is the story with
> mysql_close.  There is no mysql_pclose.  I guess you don't need to
> close the connection at the end of each page but what if you do.   Is
> mysql_close ignored if the connection was made with mysql_pconnect or
> douse it close the connection and next time mysql_pconnect is run it
> reconnects causing no benefit over mysql_pconnect.  also what is the
> timeout likely to be?

mysql_close() will almost-for-sure just ignore you if you are silly enough
to close a _pconnect() opening.

Not sure which timeout you are referring to, though...

There are several timeouts you could be asking about...

You can safely assume that the default timeouts are okay for MOST sites.

> My other question is what happens if lots of people connect using the
> same user/password.  I tend to do my own user management so everybody
> douse.  Is doing my own user management really dodge, if we were
> talking about oracle I would probably say it is.

Essentially, using _pconnect() boils down to having ONE connection for
each Apache process using the same user/pass.

Or, if you have shell users, add them in as well.

Make damn sure your /etc/my.cnf setting has a limit with a few MORE
connections than your httpd.conf has for number of Apache children.

Maybe even add a comment to that effect in both places (my.cnf and
httpd.conf), so any goofball changing either configuration file knows what
not to do.

Less MySQL connections than Apache children means some Apache children
will be starved for db, and after very short time-out waiting for db, will
just puke and die on you.

Leave a few EXTRA mysql connections, so a run-away Apache/MySQL/query
problem leaves *YOU* with the ability to log in from shell with mysql
monitor or mysqladmin to diagnose/fix/kill the thing.

Otherwise, you have to bring down all of Apache to get into your database,
if you even can, with, say, a runaway MySQL query tying up the db, and
Apache patiently waiting for that and refusing to die on anything less
than kill -9 because it's "busy"...

-- 
Like Music?
http://l-i-e.com/artists.htm

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux