Page 1 of 1

Keeping A Mysqli Connection Open

Posted: Sun May 01, 2011 10:04 am
by ChrisBull
I have a site with a control panel for users that have logged in, While logged in they will be doing a lot of actions that require a database connection which I am using pdo class with mysqli. The site is a single page site but the user could be on for over an hour for which the connection will have to remain open, the user might leave the computer for an hour and providing he hasn't logged out or closed the page the connection still needs to be open.

So is there a way to do this, I don't know how and when the connection will close automatically. I did some research and found that if i use a persistent connection it should stay open until I run the code to close it. Is this true, is there really no time limit on it? Can anyone think of another better way to do this?

Thanks For Your Time
Chris

Re: Keeping A Mysqli Connection Open

Posted: Mon May 02, 2011 12:52 am
by Christopher
In PHP, connection are created and destroyed each request. Unless you are having some performance problem, I would recommend using PHP is its "share nothing" style.

Re: Keeping A Mysqli Connection Open

Posted: Mon May 02, 2011 2:25 am
by darek
The question is WHY do you want to keep the connection open. I can't think of any situation that you really need to do that.

Re: Keeping A Mysqli Connection Open

Posted: Mon May 02, 2011 11:01 am
by oscardog
Christopher wrote:In PHP, connection are created and destroyed each request. Unless you are having some performance problem, I would recommend using PHP is its "share nothing" style.
Not entirely true, mysql_pconnect keeps a connection open. There is a thread about it here.