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()?
基础教程推荐
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何替换eregi() 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
