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
Keeping A Mysqli Connection Open
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Keeping A Mysqli Connection Open
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.
(#10850)
Re: Keeping A Mysqli Connection Open
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
Not entirely true, mysql_pconnect keeps a connection open. There is a thread about it here.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.