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,...)?