In most systems, database connections are pooled, meaning that when you give
them up, they are not completely closed but the sql client software keeps
them in a pool available for the next script asking for a similar
connection, thus saving on the time to establish a connection. It is the
connection between your script and the sql client that gets cut, the
database does not know your script is gone, since the sql client doesn't
tell it.
For the pooling to work, it is necesary that all the connections requested
have the same parameters, including user name and password. If you change
username for each page, then the client software has to actually establish a
connection for that user to retrieve the proper permisions. Of course,
that connection would also be sent to the pool once the page is processed,
but then the pool would soon fill up with many connections, one per
username, each seldom used and in a really busy server, the connection would
be dropped out of the pool before it gets a chance to be reused.
Storing those many connection in session variables only moves the problem
from having the sql client manage a large pool of little used connections to
have PHP sessions do the same thing, far more inneficiently.
The best thing is to make sure all connections you use are opened with
exactly the same parameters, use just one connection for all the script
(unless, of course, you actually have to connect to different databases) and
let it go as fast as you can to give the next in line a chance to reuse it
from the pool.
Satyam
----- Original Message -----
From: "PHP Mailing List" <php@xxxxxxxxxxxxxxxxxxx>
To: <php-general@xxxxxxxxxxxxx>
Sent: Monday, June 11, 2007 6:53 PM
Subject: MySQL Connection in Session ?
Can I maintain just one mysql connection resource to all my pages per user
session. As far as I knows create connection is more expensive than
executing queries ?
Any reference how to make efficient for connection resources ?
Thanks,
Dino
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
No virus found in this incoming message.
Checked by AVG Free Edition. Version: 7.5.472 / Virus Database:
269.8.13/843 - Release Date: 10/06/2007 13:39
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php