I can’t say for sure that all versions of PHP / Mysql on all server platforms behave the same. For tcp connections to the database - if you do not call mysql_close ($ db), you will have a tcp dangling connection that sits there, expecting it to be used for half a minute after the script ends. Then he just leaves on his own.
I can’t tell if this is a PHP garbage collection filling up the full 30 seconds, or if the tcp connection expires 30 seconds after you call the connection.
Mysql_close ($ db) instantly kills the tcp connection. So yes, I would say always call mysql_close ($ db) immediately after you no longer need the database connection in the script.
bob-the-destroyer Jun 02 '10 at 18:52 2010-06-02 18:52
source share