Zend Framework应用程序无法正确关闭mysql连接 [英] Zend Framework app not closing mysql connections properly

查看:39
本文介绍了Zend Framework应用程序无法正确关闭mysql连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Zend_Db的PDO适配器管理数据库连接时出现了一个奇怪的问题.突然之间,我不断达到MySQL服务器上的连接限制.

I'm having a weird issue using Zend_Db's PDO adapter for managing my database connections. All of a sudden, I'm constantly hitting the connection limit on my MySQL server.

无论出于什么原因,每三到四个小时左右我都会收到此错误,Apache会在每个HTTP请求中都出现此错误:

For whatever reason, every three or four hours or so I end up getting this error, and Apache craps out on every HTTP request with this error:

PHP致命错误:消息为'SQLSTATE [00000] [1129]主机'my.internal.mysql.server.DNS.here'的未捕获异常'Zend_Db_Adapter_Exception'因许多连接错误而被阻止;

PHP Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message 'SQLSTATE[00000] [1129] Host 'my.internal.mysql.server.DNS.here' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'' in

奇怪的是,我没有更改任何代码,流量实际上比过去减少了,所以我知道我的应用程序不应该生成更多的并发连接.最奇怪的是,我已经近一个星期没有更改任何主应用程序文件上的代码了,此后一切都畅通无阻.

The weird thing is, I haven't changed any code and traffic volumes are actually down from what they've been in the past, so I know my app shouldn't be generating more concurrent connections. The weirdest thing is I haven't changed code on any of the main app files in nearly a week and everything has ran swimmingly since.

重新启动mysql服务或使用mysqladmin flush-hosts刷新连接确实可以解决问题,我敢肯定,增加my.cnf中的最大并发连接数也将有助于缓解其中的一些问题,但是似乎存在一些问题.应用程序本身创建太多连接的核心问题.

Rebooting the mysql service or flushing the connections with mysqladmin flush-hosts does do the trick, and I'm sure increasing the max concurrent connections in my.cnf would also help alleviate some of these issues, but there seems to be a core problem with the application itself creating too many connections.

是否有关于如何深入挖掘并关联导致挂起连接的代码段的想法?从外部看,Web应用程序的所有不同页面都可以很好地加载并具有良好的速度.

Any thoughts on how I can drill down and correlate the piece of code causing the hanging connection? Externally, all of the different pages of the web app load fine and with good speed.

推荐答案

我认为您的脚本之一正在运行超长查询或卡住?

I think one of your script is running an ultra long query or get stuck ?

最好的解决方案是创建一个日志记录工具,并使用该工具来知道问题出在哪里.

The best solution would be to create a logging tool and use that to know where exactly the problem is.

Zend_Log 类应该帮助您编写该日志记录工具,显然,最好是使用一个文件编写器而不是一个数据库编写器.由于您的问题与数据库有关,因此您应该创建或修改数据库类以发出一些日志.

The Zend_Log classes should help you to write that logging tool, obviously you have better to user a file writer and not a DB one. Since your problem is DB related you should create or modify the DB class to emit some logs.

我不知道您的项目的体积,但它可能会有一些性能方面的副作用.

I don't know the volumetric of your project but it might have some performance side effects.

还要使用长查询 MySQL的功能可能会给您一些提示.

Also playing with the long query feature of MySQL would probably give you some hint.

希望您会发现问题出在哪里.

Hope you are going to find where is your problem.

这篇关于Zend Framework应用程序无法正确关闭mysql连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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