Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are mysql_close and pg_close required? [duplicate]

Possible Duplicate:
using mysql_close()

Are mysql_close and pg_close required ?

In some script there aren't... why ?

What happen if I don't use its ?

like image 458
xRobot Avatar asked Jun 08 '10 11:06

xRobot


2 Answers

Why don't you read it in the PHP reference manual? All information is there...

  • http://www.php.net/mysql_close
  • http://www.php.net/pg_close
  • http://www.php.net/manual/en/language.types.resource.php#language.types.resource.self-destruct

But in a nutshell : no they are not necessary, but imho it's better to close the connections yourself to free resources asap when you no longer need them.

like image 151
wimvds Avatar answered Sep 28 '22 01:09

wimvds


If you don't call it, the socket connection to the database remains open for ~30 seconds in a wait state.

If you get lots and lots of people and you don't somehow manage to reuse these zombie connections, your database might explode with a too many users error.

So in answer to your question: syntactically not required but it's very poor practice not to include them.

like image 37
Oli Avatar answered Sep 28 '22 02:09

Oli