为什么要使用 mysqli_close()?

2023-03-06php开发问题
6

本文介绍了为什么要使用 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()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17