如何关闭未关闭的mysql连接? [英] How to close unclosed mysql connections?

查看:662
本文介绍了如何关闭未关闭的mysql连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于太多未关闭的mysql连接,我的托管服务提供商的客户端阻止了该站点. 该网站以前是由某人创建的,目前我正在维护.

My clients hosting provider blocks the site because of too much unclosed mysql connections. the site was previously created by someone and currently I'm maintaining it.

我在页面末尾添加了mysql_close函数.它很好地关闭了连接,但是我仍然有一些未关闭的连接.我可能会留在哪里.

I have addded the mysql_close function at the end of the pages. It is closing the connections good but still I'm getting some connections left unclosed. I may left some where..

我需要使用cron文件或其他方法关闭服务器中未关闭的mysql连接.

What I need is to close the unclosed mysql connections in the server using a cron file or some thing..

我该怎么办?

是否可以一次关闭所有连接?如果可以,怎么办?

推荐答案

您是否正在使用持久连接?如果没有,那么您真的不必担心关闭连接.从手册

Are you using persistent connections? IF not, then you really shouldn't worry too much about closing your connections. From the manual

通常不使用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.

不是有太多的未关闭连接,而是您有太多的打开连接(当然,这基本上是相同的)吗?例如,一次您的网站上有太多用户?

Instead of too_much unclosed connections, couldn't it be (which is essentially the same ofcourse) that you have too many open connections? For instance, too many users on your site at once?

如果您具有持久连接,请不要忘记以下内容:

If you do have persistent connections, do not forget this:

mysql_close()将不会关闭 由创建的永久链接 mysql_pconnect().

mysql_close() will not close persistent links created by mysql_pconnect().

如评论中所述,mysql_connect()资源在脚本末尾未释放的可能性很小.从另一个手册页

As said in the comment, it is highly unlikely that a mysql_connect() resource is not freed at the end of the script. From another manual page

释放资源

感谢引用计数 PHP 4的Zend引入的系统 引擎,没有更多的资源 检测到对它的引用 自动,并且由 垃圾收集器.因此,它 很少需要释放内存 手动.

Thanks to the reference-counting system introduced with PHP 4's Zend Engine, a resource with no more references to it is detected automatically, and it is freed by the garbage collector. For this reason, it is rarely necessary to free the memory manually.

注意:持久数据库链接是一个 此规则的例外.他们不是 被垃圾收集器摧毁. 请参阅持久连接部分 有关更多信息.

Note: Persistent database links are an exception to this rule. They are not destroyed by the garbage collector. See the persistent connections section for more information.

但是,在 mysql_close页上的注释中,可能会有一个旁注

There could be a sidenote however, from the comments on the mysql_close page

至少对于PHP5.3.2和Windows 通过TCP连接,你应该总是 使用此mysql_close()函数来 关闭并释放tcp套接字 由PHP使用.垃圾收集后 脚本执行不会关闭 tcp套接字本身.插座 否则将保持等待"状态 大约30秒,以及任何 额外的页面加载/连接 尝试只会增加总数 打开的TCP连接数.这 等待时间似乎不是 可通过PHP设置进行配置.

At least with PHP5.3.2 and Windows connecting by tcp, you should always use this mysql_close() function to close and free up the tcp socket being used by PHP. Garbage collection after script execution does not close the tcp socket on its own. The socket would otherwise remain in 'wait' state for approximately 30 seconds, and any additional page loads/connection attempts would only add to the total number of open tcp connections. This wait time does not appear to be configurable via PHP settings.

这篇关于如何关闭未关闭的mysql连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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