为什么要使用mysqli_close()? [英] Why use mysqli_close()?

查看:586
本文介绍了为什么要使用mysqli_close()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在查询之后或脚本结尾是否应该关闭连接?

Is there any reason why I should close the connection after a query or at the end of the script?

做/不做的好处是什么?

What are the benefits of doing/no doing do?

推荐答案

连接(如果不是持久性的)始终在脚本结尾处关闭,因此,从理论上讲,您不会需要自己关闭它.

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()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆