Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ixudra's avatar

Laravel queries

I was wondering exactly how queries are handled in Laravel. for a while now, we are experiencing some issues on our database server. At some times, for no apparent reason, our app can no longer connect to the database and collect information from it:

[2016-04-15 12:17:39] production.ERROR: 
exception 'PDOException' with message 'SQLSTATE[HY000] [2003] 
Can't connect to MySQL server on 'db-001.server.com' 
(99 "Cannot assign requested address")' in 
/path/to/app/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:55

This happens on random times, even in the middle of the night when nobody is actually using the app. The issue always resolves itself after a minute or two, but it's a huge problem if you are actually working on something important at that particular moment.

I've contacted the hosting support and they expect it to be some kind of pooling issue, saying that laravel is making too many database connections and not closing them properly. Hence my question: how does this work in Laravel? Is every query a new connection or is this handled more gracefully (per transaction,...)?

0 likes
1 reply
renedekat's avatar

@Elimentz Are you sure that your DB or DB server isn't doing some maintenance when this occurs? Do you have the artisan scheduler enabled and if so, what does it do? Perhaps you're running some heavy queries.

Have you checked your application for errors? On some errors, a connection might not be closed properly.

As always: log files are you friend :)

Please or to participate in this conversation.