Why should I close a mysql connection?
Is it necessary to close it?
Why to close a mysql connection?
Moderator: General Moderators
-
klevis miho
- Forum Contributor
- Posts: 413
- Joined: Wed Oct 29, 2008 2:59 pm
- Location: Albania
- Contact:
Re: Why to close a mysql connection?
The connection will close when the script ends. Sometimes, for a long running script it is better to close the connection after it is no longer needed to free up resources. For 99% of all cases you shouldn't need to close it manually
-
klevis miho
- Forum Contributor
- Posts: 413
- Joined: Wed Oct 29, 2008 2:59 pm
- Location: Albania
- Contact:
Re: Why to close a mysql connection?
Thnx pytrin.
Re: Why to close a mysql connection?
Right on the money! In a system I recently developed t hat runs from the command line in both Windows and Linux will leak memory if you are not religous aboutpytrin wrote:The connection will close when the script ends. Sometimes, for a long running script it is better to close the connection after it is no longer needed to free up resources. For 99% of all cases you shouldn't need to close it manually
closing your connections.
My suspicion is that you are most likely better off to tell PHP exactly what you want it to do as opposed to letting it figure it out on it's own. In this case, it's going to make the right choice all the time, but my concern is more related to the associated overhead of the intelligence required to make this kind of thing work.
Re: Why to close a mysql connection?
There is no "intelligence" or "figuring out things". When a script finishes executing, it releases all the resources it used.
Re: Why to close a mysql connection?
And of course you're right. I was thinking of other phases of script execution.pytrin wrote:There is no "intelligence" or "figuring out things". When a script finishes executing, it releases all the resources it used.
-
heronfisher
- Forum Newbie
- Posts: 4
- Joined: Thu Mar 11, 2010 3:52 am
Re: Why to close a mysql connection?
When using something like cgi, it's completely unnecessary to close your mysql connections since they close automatically at the end of script execution. When using persistent technologies , which maintain your connections between requests, then it's important to keep track of connections, global variables, etc..