DB failover settings in .env file? |
The docs talk about a database 'failover' parameter, which is defined as an array within the main DB connection settings.
Is there a way to define failovers in an .env file? If so, what would that syntax be? Is it as simple as doing it like? database.default.failover.hostname = myserver.com Designer, developer and Diet Dr. Pepper addict. Messing up PHP since <?= $when['year';] ?>
Did some testing today and sadly it doesn't seem to work. The browser spins for a few seconds and then says "Connection timed out" instead of looking for the failover connection.
Here's what I've got: Code: database.default.hostname = primaryserver.com Any ideas? Designer, developer and Diet Dr. Pepper addict. Messing up PHP since <?= $when['year';] ?>
Failover functionality is currently broken because we always throw an exception when there is something wrong with the connection. I prepared a fix for this: https://github.com/codeigniter4/CodeIgniter4/pull/3074 - hopefully it will be accepted soon.
One thing you have to remember when it comes do .env file. You can only override values that are already defined in the original config file - in this case in database.php, so you need to prepare empty variables in failover array. The other thing is that failover array can have multiple entries so in your .env file it should look something like this: PHP Code: database.default.failover.0.hostname = secondaryserver.com
Thanks so much for looking at that Michalsn! And good info about the .env needing to override existing settings.
Designer, developer and Diet Dr. Pepper addict. Messing up PHP since <?= $when['year';] ?>
|
Welcome Guest, Not a member yet? Register Sign In |