composer require tinywan/load-balancing
// 服 务器数
$services = [
'192.168.10.1' => 5,
'192.168.10.2' => 1,
'192.168.10.3' => 1,
];
// 使用 平滑 加 权算法 (Smooth Weighted Round Robin)
$robin = new \Robin\SmoothWeightedRobin();
$robin->init($services);
$nodes = [];
$sumWeight = $robin->getSumWeight();
for ($i = 1; $i <= $sumWeight; $i++) {
$node = $robin->next();
$nodes[$i] = $node;
}
var_export($nodes);
// 会 生成 如下均 匀序列
array (
1 => '192.168.10.1',
2 => '192.168.10.1',
3 => '192.168.10.2',
4 => '192.168.10.1',
5 => '192.168.10.3',
6 => '192.168.10.1',
7 => '192.168.10.1',
)