与Laravel 5.4和Mariadb的连接错误太多

时间:2022-10-15 19:55:46

I have recently upgraded my laravel app from 5.1 to 5.4. My server is now on PHP 7 and Maria db 10.1.22. Now I am getting a really weird error. Sometimes, I would just try to refresh my browser and PHPMyAdmin would display #1040 - Too many connections. Other times I would click on a new link on my app and then would get this same error. I did some research on the internet and executed the command below:

我最近将laravel应用从5.1升级到5.4。我的服务器现在在PHP 7和Maria db 10.1.22上。现在我得到了一个很奇怪的错误。有时,我会试着刷新浏览器,PHPMyAdmin会显示#1040 -太多的连接。有时我会点击app上的一个新链接,然后会得到同样的错误。我在互联网上做了一些研究,执行了以下命令:

show variables like 'max_connections`

The above command gave 100. Which I then increase to 500.

上面的命令给出100。然后增加到500。

But now I still get the error. This is weird to me because I have oracle mysql 5.6 installed on another server and max_connections is 151 and for over a year and a half I have not experienced this error.

但现在我还是得到了误差。这对我来说很奇怪,因为我在另一台服务器上安装了oracle mysql 5.6, max_connections是151,而且一年半以来我都没有遇到过这种错误。

When I run the command show processlist, I get the result below and this keeps increasing. is this normal?

当我运行命令show processlist时,我得到了下面的结果,并且这个结果一直在增加。这是正常的吗?

与Laravel 5.4和Mariadb的连接错误太多

What could be the issue with Mariadb and how can I fix it.

Mariadb的问题是什么,我该如何解决它。

3 个解决方案

#1


3  

I am not sure if you guys found the solution or not but I was facing the same problem as well and found the solution. As we upgraded our laravel application from 5.2 - 5.4, we missed something important. php artisan queue:work has been upgraded as well.

我不确定你们是否找到了解决方案但我也面临着同样的问题找到了解决方案。当我们从5.2 - 5.4升级laravel应用程序时,我们错过了一些重要的东西。php artisan队列:工作也已升级。

In laravel 5.2, when we execute queue:work. It just process one job at a time but in laravel 5.4 queue:work creates a connection for your queue and keeps it connected. So if you have queue:work in your cron to run every minute it will create a new connection every minute and that is why we get the error of too many connections.

在laravel 5.2中,当我们执行队列:工作。它一次只处理一个作业,但在laravel 5.4队列中:work为您的队列创建一个连接并保持它的连接。如果你有queue:在cron中运行每一分钟它每一分钟都会创建一个新的连接这就是为什么我们会得到太多连接的错误。

I did not find this information on laravel 5.4 documentation. I was going through php artisan to see the description of queue:work and found out that the description is changed.

我没有在laravel 5.4文档中找到这些信息。我正在浏览php artisan以查看queue:work的描述,然后发现描述被更改了。

This is description in laravel 5.2:

这是laravel 5.2的描述:

queue:work >>>> Process the next job on a queue

队列:工作>>>>处理队列上的下一个作业

This is description in laravel 5.4

这是laravel 5.4中的描述

queue:work >>>> Start processing jobs on the queue as a daemon

队列:工作>>>>作为守护进程开始处理队列上的作业

As you can see the difference in what they are meant to do.

正如你所看到的,他们的目的不同。

I hope that this helps you out.

我希望这能帮助你。

Thanks.

谢谢。

#2


0  

Maybe it is a silly observation, but did you use DB::disconnect('foo') to closes the conenctions of your db?

也许这是一个愚蠢的观察,但是您是否使用DB::disconnect('foo')来关闭您的DB ?

Anyway, the db closes automatically, so the problem may be somewhere else, did you try monitoring?

无论如何,db自动关闭,所以问题可能在其他地方,您尝试过监控吗?

A very powerful tool to monitor MySQL is innotop. You can find it here:

innotop是一个非常强大的MySQL监控工具。你可以在这里找到:

https://github.com/innotop/innotop

https://github.com/innotop/innotop

Check this

检查这个

#3


0  

What webserver are you using. If Apache, then what is the setting of MaxRequestWorkers (formerly called MaxClients) for it? Generally it should be no more than about 20.

您正在使用什么webserver。如果是Apache,那么maxrequestworker(以前称为maxclient)的设置是什么?通常应该不超过20。

If that is set to more than max_connections, that would explain what you are seeing.

如果将其设置为大于max_connections,就可以解释所看到的内容。

#1


3  

I am not sure if you guys found the solution or not but I was facing the same problem as well and found the solution. As we upgraded our laravel application from 5.2 - 5.4, we missed something important. php artisan queue:work has been upgraded as well.

我不确定你们是否找到了解决方案但我也面临着同样的问题找到了解决方案。当我们从5.2 - 5.4升级laravel应用程序时,我们错过了一些重要的东西。php artisan队列:工作也已升级。

In laravel 5.2, when we execute queue:work. It just process one job at a time but in laravel 5.4 queue:work creates a connection for your queue and keeps it connected. So if you have queue:work in your cron to run every minute it will create a new connection every minute and that is why we get the error of too many connections.

在laravel 5.2中,当我们执行队列:工作。它一次只处理一个作业,但在laravel 5.4队列中:work为您的队列创建一个连接并保持它的连接。如果你有queue:在cron中运行每一分钟它每一分钟都会创建一个新的连接这就是为什么我们会得到太多连接的错误。

I did not find this information on laravel 5.4 documentation. I was going through php artisan to see the description of queue:work and found out that the description is changed.

我没有在laravel 5.4文档中找到这些信息。我正在浏览php artisan以查看queue:work的描述,然后发现描述被更改了。

This is description in laravel 5.2:

这是laravel 5.2的描述:

queue:work >>>> Process the next job on a queue

队列:工作>>>>处理队列上的下一个作业

This is description in laravel 5.4

这是laravel 5.4中的描述

queue:work >>>> Start processing jobs on the queue as a daemon

队列:工作>>>>作为守护进程开始处理队列上的作业

As you can see the difference in what they are meant to do.

正如你所看到的,他们的目的不同。

I hope that this helps you out.

我希望这能帮助你。

Thanks.

谢谢。

#2


0  

Maybe it is a silly observation, but did you use DB::disconnect('foo') to closes the conenctions of your db?

也许这是一个愚蠢的观察,但是您是否使用DB::disconnect('foo')来关闭您的DB ?

Anyway, the db closes automatically, so the problem may be somewhere else, did you try monitoring?

无论如何,db自动关闭,所以问题可能在其他地方,您尝试过监控吗?

A very powerful tool to monitor MySQL is innotop. You can find it here:

innotop是一个非常强大的MySQL监控工具。你可以在这里找到:

https://github.com/innotop/innotop

https://github.com/innotop/innotop

Check this

检查这个

#3


0  

What webserver are you using. If Apache, then what is the setting of MaxRequestWorkers (formerly called MaxClients) for it? Generally it should be no more than about 20.

您正在使用什么webserver。如果是Apache,那么maxrequestworker(以前称为maxclient)的设置是什么?通常应该不超过20。

If that is set to more than max_connections, that would explain what you are seeing.

如果将其设置为大于max_connections,就可以解释所看到的内容。