a module for managing multi-site sites

At the moment I’m implementing a module for managing multi-site sites

It would be desirable to implement switching a choice of a site in backend and accordingly change settings database connection on the fly


Sites /

Default /

Site1 /

Site2 /
The work is done on the default site. After selecting in the admin panel – “work at site1”, its settings are loaded in default on the fly without changing the settings.php. In particular, only the connection settings of the database change

Tried the following methods

Changing the active connection according to the default-extra scheme

Drupal Core Database Database :: setActiveConnection (‘extra’);

Did not work out
I tried at the initialization level to place a call at the initialization level

Did not work out
Is it possible to do this? There is an idea on putting a variable in a session and in settings.php checking it. But how to access it from settings.php?

Drupal version: 

Source: https://www.drupal.org/taxonomy/term/4/feed