cameronasmith's avatar

Does Laravel/PHP keep pooling for database connections.

I have some middleware that sets the SEARCH_PATH for the current connection to {shema, public}.

My question is that when a connection is closed or still active does PHP/Laravel share that connection between each other instead of opening a new connection.

I'm worried that the search_path will be shared with other people who pick up the same connection.

Does anyone have any documentation proving this too?

Thanks,

Cameron.

0 likes
3 replies
jlrdw's avatar

After a query has completed the connection is closed. Edit: As the server handles this stuff in the background, you probably need not worry about it.

jimmck's avatar

@cameronasmith Connection pooling is typically handled by the webserver, but is subject to the architecture of server process. MySQL has it for MySQL-I drivers. Using a different connect string will use a pooled connection in place of creating a new one. There is less overhead in reusing one vs. creating a new network connection each time. But remember connections are a finite and valuable resource.

http://php.net/manual/en/mysqli.persistconns.php

https://www.google.com/search?q=mysqli+connection+pool+apache&oq=mysqli+connection+pool+apache&aqs=chrome..69i57.15704j0j7&sourceid=chrome&ie=UTF-8

Different drivers/databases can treat pooling differently.

Please or to participate in this conversation.