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
https://forums.phpfreaks.com/topic/93917-use-of-mysql_free_result-and-mysql_close/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.