Why use mysqli_close()?(为什么要使用 mysqli_close()?)
问题描述
有什么理由让我在查询之后或脚本结束时关闭连接吗?
Is there any reason why I should close the connection after a query or at the end of the script?
做/不做有什么好处?
推荐答案
连接(如果不是持久的) 总是在脚本结束时关闭,所以,理论上,你不会需要自己关闭.
The connection (if not persistent) is always closed at the end of the script, so, in theory, you don't need to close it yourself.
不过,如果您的 PHP 脚本需要大量时间来执行,那么当您不再需要对数据库执行任何请求时关闭连接是个好主意——至少,如果长时间的计算是在之后完成的查询.
Still, if your PHP script takes lots of time to execute, it's a good idea to close the connection when you don't have to do any request to the database anymore -- at least, if the long calculations are done after the queries.
如果您的应用程序部署在共享主机上,则尤其如此:您的用户帐户通常只能同时打开几个连接.(在共享主机上,同时打开的连接数量可能很少;在私人服务器上通常更大).
This is especially true if your application is deployed on a shared hosting : your user account can generally only have a few connections opened at the same time. (That number of simultaneous opened connections can be pretty small on shared hosting ; it's generally bigger on private servers).
我们经常不关闭自己的联系的原因是:
The reason we often don't close connections ourselfves is :
- 我们通常不知道何时完成了所有查询——对于由许多小块"组成的页面尤其如此;每一个都是独立于其他的,并且可以自己进行查询;那么,我们什么时候可以关闭连接?
- 网页的生成速度通常非常快,因此我们不必担心关闭与数据库的连接.
这篇关于为什么要使用 mysqli_close()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么要使用 mysqli_close()?


基础教程推荐
- 在多维数组中查找最大值 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01