Laravel 5.6 booting is extremely slow when the DB is external to the server

I have a Laravel 5.6 application with legacy code and I am willing to fix and upgrade, but first I wanted to separate the web application from the DB.

With the debugbar I have seen that when the APP connects to the local mysql the booting takes 100ms. When it connects to the remote database, the booting takes 2seconds.

debugbar in with local bd and remote bd

I have debugged how long it takes to make a query with a select (like DB::table('users')->limit(100)->get()) and the query executes fast both locally and remotely, so I can rule out a latency issue or a database problem.

In addition, I have created a url with a simple controller that only returns a static html to make the tests and that there are no strange things that can make the legacy code.

I also have to say that the tests have been done with different servers, with the same versions and the booting problem always occurs. In production I use mariaDB 10.5 but in development I have a mysql 8, I have done the same tests with both versions and always the same thing happens, local fast, remote slow.

Could someone give me some help?