MySQL Forums
Forum List  »  PHP

Re: Persistent Connection
Posted by: Scotty Miller
Date: July 22, 2008 02:45AM

MySQL will create a persistent connection for each user who views the website. Before one decides to use mysql_pconnect(), one should analyze whether or not it is necessary. If your scripts are having to make a lot of individual connections to a database in one 'session' so to speak, then a persistent connection may make more sense. On the flip side, persistent connections can often cause a lot of connections that will bombard the server, even those remaining from users who are no longer viewing the site. If I remember correctly, the server (by default) will maintain a persistent connection for 8 hours. This can be modified in the settings in the wait_timeout directive. Typically, 60 seconds would probably suffice. Potentially having thousands of hits in 8 hours, thousands of open connections, it will kill the MySQL server. Now a thousand connections over 8 hours with a 60 second timeout will allow for the server to breathe easier when making that caliber of connections.

As far as the connection process goes. If a mysql_pconnect() function is called on a page, it will initiate the open connection, and if it is made again elsewhere, it will look to see if a persistent connection is already open. If it is, it will use that connection, if not, it will create a new one.

Options: ReplyQuote


Subject
Written By
Posted
July 21, 2008 07:28PM
Re: Persistent Connection
July 22, 2008 02:45AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.