[UPHPU] Freeing database resources

Rusty Keele rusty.keele at yahoo.com
Tue Jun 3 16:12:42 MDT 2008


Hi,

    I very rarely free up my resources when using PHP to interact with a MySQL database.  I figure that the garbage collector will do an adequate job.  In fact the PHP manual says: "Thanks to the reference-counting system introduced with PHP 4's Zend Engine, a resource with no more references to it is detected automatically, and it is freed by the garbage collector."

    However, I notice that in the same PHP manual they always free up their resources in the examples they give!  Why do they do that if the resources are garbage collected?  Perhaps they are just being careful coders and demonstrating best practices.  Anyway, I am wondering if anybody has ever had problems by NOT freeing up MySQL resources - you know, by not calling mysql_close() or mysql_free_result().

    Also, I mostly use the MySQL Improved Extension (mysqli_x) functions and methods, and I assume they work the same way by automatically garbage collecting unfreed resources, but I'm not 100% sure.  Does anybody know?

See:
 http://www.php.net/manual/en/language.types.resource.php#language.types.resource.self-destruct
 http://www.php.net/manual/en/function.mysql-connect.php
 http://www.php.net/manual/en/mysqli.connect.php

Thanks,
-Rusty


       


More information about the UPHPU mailing list