Mikaele
Mikaele

Reputation: 75

How to use master & slave nodes in Laravel

We're having 2 nodes for reading and 1 for writing. How can I set in my code the connection to these 2 reading nodes and on every page load to choose randomly between both (I don't know if it must be random or somehow to determinate which node is more free). Also any suggestions on how to set up the connection with the master node and how to actually use it? I've never done that and every help is appreciated! My project is on Laravel 8.

Upvotes: 0

Views: 1161

Answers (1)

Sergei Shitikov
Sergei Shitikov

Reputation: 317

You can use Read & Write connections feature: https://laravel.com/docs/9.x/database#read-and-write-connections

Then just set write host for your master and read hosts for your slaves. Hope this will help.

Upvotes: 1

Related Questions