Monday, July 27, 2009

Connection Pooling & MYSQL

Connection Pooling - Database
In software engineering, a connection pool is a cache of database connections maintained by the database so that the connections can be reused when the database receives future requests for data. Connection pools are used to enhance the performance of executing commands on a database. Opening and maintaining a database connection for each user, especially requests made to a dynamic database-driven website application, is costly and wastes resources. In connection pooling, after a connection is created, it is placed in the pool and it is used over again so that a new connection does not have to be established. If all the connections are being used, a new connection is made and is added to the pool. Connection pooling also cuts down on the amount of time a user must wait to establish a connection to the database.
Definition and Usage - mysql_pconnect()
The mysql_pconnect() function opens a persistent MySQL connection.
This function returns the connection on success, or FALSE and an error on failure. You can hide the error output by adding an '@' in front of the function name.
mysql_pconnect() is much like mysql_connect(), but with two major differences:
• This function will try to find a connection that's already open, with the same host, username and password. If one is found, this will be returned instead of opening a new connection
• The connection will not be closed when the execution of the script ends (mysql_close() will not close connection opened by mysql_pconnect()). It will stay open for future use

No comments:

Post a Comment