Pankaj Agrawal
Pankaj Agrawal

Reputation: 203

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...

Upvotes: 8

Views: 22611

Answers (1)

SergkeiM
SergkeiM

Reputation: 4168

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

Upvotes: 7

Related Questions