Keeping A Mysqli Connection Open

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ChrisBull
Forum Commoner
Posts: 42
Joined: Fri Aug 20, 2010 7:43 am

Keeping A Mysqli Connection Open

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Keeping A Mysqli Connection Open

Post 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.
(#10850)
darek
Forum Newbie
Posts: 8
Joined: Tue Apr 19, 2011 2:26 am
Location: Opole, Poland

Re: Keeping A Mysqli Connection Open

Post 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.
oscardog
Forum Contributor
Posts: 245
Joined: Thu Oct 23, 2008 4:43 pm

Re: Keeping A Mysqli Connection Open

Post 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.
Post Reply