简体   繁体   中英

PHP:MySQL what if we don't close the opened connections

In PHP + MySQL

This is:

$conn = mysql_connect("server","user","pass");
mysql_select_db("datbasename");

what we do to open a connection.

And this is:

mysql_close($conn);

what we do to close the connection.

  • WHAT if we don't close the connections? What are going to be the effects?
  • After what CONDITION the opened connections are automatically closed?

From the PHP documentation for mysql_close :

Using mysql_close() isn't usually necessary, as non-persistent open links are automatically closed at the end of the script's execution. See also freeing resources.

With mysql_connect connection will close, when script is ended.

mysql_pconnect doesn't close connection.

If you work with more then 1 mysql servers, is necessery to control your closing connections, or create some persistance.

In a small application nothing at all. PHP is nice and cleans up memory/closes connections upon scripts execution completion. If you are concerned about resources and utilization then I suggest closing your connections when you are finished using them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM