Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Closing database connection In Laravel 5.1

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.

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

Thanks in advance...

like image 434
Pankaj Agrawal Avatar asked Dec 21 '16 07:12

Pankaj Agrawal


1 Answers

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.

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

like image 83
Froxz Avatar answered Oct 05 '22 13:10

Froxz