错误“连接过多"在 CodeIgniter 网站上 [英] Error "too many connections" on CodeIgniter website

查看:27
本文介绍了错误“连接过多"在 CodeIgniter 网站上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了有关堆栈溢出的所有关于此主题的问题/答案,但不幸的是,没有一个能解决我的问题.

I've already read all the questions / answers about this subject here on stack overflow but unfortunately none have resolved my problem.

最近几天,网站日志中不断出现 mysql 错误连接过多",并且每个客户端都挂起整个网站.实际上它挂掉了服务器上的所有网站.

In the last few days the mysql error "too many connections" keeps showing up on the website logs and it hangs the entire website for every client. In fact it hangs all the websites on the server.

这里是我的问题/评论:

So here are my questions / remarks:

  • 大约有 50 个不同的客户端数据库,除了所有客户端通用的 2 个
  • pconnect 对于所有连接已经 = FALSE
  • 在文件php.ini"上,变量allowpersistent"为ON.即使我写 pconnect = FALSE,这是否会使 mysql 连接永久化?(我无法更改allowpersistent"变量,必须询问托管公司)
  • 加载数据库有3个文件,一个加载客户端的数据库,另外两个加载所有客户端的公共数据库,它们在每个模型的构造方法上调用,但是CI应该在完成后关闭mysql连接它们并忽略任何已加载的加载->数据库"
  • "db->close" 显然什么都不做,因为 this->db->database 在我关闭它后保持它的值 :P
  • 当我写这篇文章时,Threads_connected 最多 1000 个,但网站已关闭:(
  • mysql 配置有 max_connections = 1000,可以进一步增加吗?我看不到可用内存的变化,那么会发生什么?
  • 我应该改为 PDO 吗?我正在使用数据库驱动程序mysqli"
  • 我是否应该要求托管公司降低mysql变量'wait_timeout',以便快速关闭数据库连接?
  • 我应该更新 CodeIgniter 吗?我有 3.1.4 版,现在是 3.1.9

非常感谢您的帮助!

推荐答案

在我们的例子中,解决方案是将 mysql 变量wait_timeout"从 8 小时(默认值,wtf!?)降低到 180 秒.如果需要,它仍然可以降低更多.这必须由托管公司完成,因为我们没有对服务器的根访问权限.

In our case the solution was lowering the mysql variable "wait_timeout" from 8 hours (the default, wtf!?) to 180 seconds. And it can still be lowered more if needed. This had to be done by the hosting company, as we do not have root access to our server.

我在问题中提到的所有其他解决方案都不起作用,例如pconnect = false"和db->close".

All the other solutions I mentioned in the question were not working, like "pconnect = false" and "db->close".

Threads_connected"现在总是低于 100 或 200,而不是这次修复之前的近 1000.

"Threads_connected" are now always under 100 or 200, instead of the almost 1000 from before this fix.

我的团队与这个问题搏斗了两天,网上有很多人在寻求解决方案,但没有任何(有效的)答案.

My team wrestled with this problem for two days, and there's lots of people on the Web asking for solutions but without any (working) answers.

干杯:)

这篇关于错误“连接过多"在 CodeIgniter 网站上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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