0

In Laravel, the database configuration enables to separate DB connection for read and write. And also it supports using multiple hosts for each action(read&write).

'mysql' => [
    'read' => [
        'host' => [
            '192.168.1.1',
            '196.168.1.2',
        ],
    ],
    'write' => [
        'host' => [
            '196.168.1.3',
        ],
    ],
    'sticky' => true,
    'driver' => 'mysql',
    'database' => 'database',
    'username' => 'root',
    'password' => '',
    'charset' => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
    'prefix' => '',
],

My question here is that when I set up the multiple hosts like above, does the framework equally distribute DB connection to each host or does it use one main host (e.g. the first host (192.168.1.1) of the array) and others as sub host?

smchae
  • 1,035
  • 3
  • 17
  • 39
  • "When multiple values exist in the host configuration array, a database host will be randomly chosen for each request." - Laravel documentation. https://laravel.com/docs/9.x/database#read-and-write-connections – user3532758 Mar 24 '22 at 01:22
  • oh i miss that part out, bc i only check my version of laravel doc. thank you for the comment – smchae Mar 24 '22 at 02:37

0 Answers0