|
Posted by Richard Lynch on 02/07/05 21:34
Tony Di Croce wrote:
> OK... Here's a slightly different, but related question...
>
> Can database connection resources be serialiazed and re-used in a
> different script invocation? For example, can I open a DB connection,
> assign it to a $_SESSION[] variable and then later use it on a
> different page? Somehow, I doubt it...
The closest you can come to that is with mysql_pconnect (or xxx_pconnect).
When you wade through the cruft, it basically boils down to each Apache
child process holding onto a connection.
You therefore MUST configure MySQL through /etc/my.cnf to have AT LEAST
that many connections available (the number of Apache children)
Actually, you want a few SPARE MySQL connections, so you can use the mysql
command line monitor to do things -- Particularly in case of a run-away
PHP/MySQL script which slams the server into over-drive... If you don't
have a connection available cuz they're all used up by Apache/_pconnect,
you can't log into mysql monitor and you can't use mysqladmin to bring it
down nicely and... Don't do that. :-)
http://php.net/mysql_pconnect
You are correct that trying to preserve the connection through $_SESSION
or other ways to cross from script to script will fail miserably. This is
true even with _pconnect, which should probably not be called "persistent"
but, rather, "re-usable" as it really ends up being "persistent" only in
MySQL space, and Apache/PHP still need to "rebuild" the connection, but
it's WAY faster cuz MySQL has it sitting there ready and waiting for you,
instead of starting from scratch each time.
--
Like Music?
http://l-i-e.com/artists.htm
[Back to original message]
|