Jump to content

use of mysql_free_result() and mysql_close()


Mario F.

Recommended Posts

Hello all,

 

Despite instructions from the PHP manual I want to use mysql_free_result() and mysql_close() consistently across my scripts. It's a matter of programming culture I acquired from other programming languages and I find it hard to let go, even during my apprenticeship of PHP.

 

What I would like to know however is if by explicitly freeing these two resources, I may be losing the edge on some internal advantage I'm not aware of like memory pooling (in place for many servers, I hear) or garbage collecting that would take care of freeing the resources at more convenient times.

 

I apologize for the assumptions in my question. I just don't know PHP well enough yet not to make them.

Link to comment
Share on other sites

PHP has page scope for all variables. If you open a connection to a DB at the begining of a script it is closed at the end for you. The only time you may want to close a connection is when you need to connect to more that one server in a page script.

 

If your script has more than one result set then, yes, you may want to save memory by freeing the results, particularly if they are large.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.