postgresql 在 Laravel 5.1 中关闭数据库连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41257347/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 02:28:18  来源:igfitidea点击:

Closing database connection In Laravel 5.1

phpdatabasepostgresqldatabase-connectionlaravel-5.1

提问by Pankaj Agrawal

Is that possible to close the database connection after running each database query in Laravel 5.1. I have already built an application by using the Laravel 5.1 and PostgreSQL, and in my server there are limited number of connections has been provided to connect with the database, that's why sometimes I am getting the error "To Many Connections". So please tell me how I can resolve this problem.

在 Laravel 5.1 中运行每个数据库查询后是否可以关闭数据库连接。我已经使用 Laravel 5.1 和 PostgreSQL 构建了一个应用程序,并且在我的服务器中提供了有限数量的连接来连接数据库,这就是为什么有时我会收到错误“To Many Connections”。所以请告诉我如何解决这个问题。

I am not sure if Laravel automatically closes the db connection after each db request.

我不确定 Laravel 是否在每个数据库请求后自动关闭数据库连接。

Thanks in advance...

提前致谢...

采纳答案by Froxz

You could use DB::disconnect('foo');But keep in mind Laravel closes connection to DB automatically at the end of the script. So your problem is somewhere else.

您可以使用DB::disconnect('foo');但请记住,Laravel 在脚本结束时自动关闭与 DB 的连接。所以你的问题在其他地方。

Workaounrd here would be unlimit connection from localhostor for particular user. Because each visitor of your website opens a new connection to DB

Workaounrd 在这里将是来自localhost或针对特定的无限连接user。因为您网站的每个访问者都会打开一个与 DB 的新连接