php-http / random-host-plugin
Client-side round robin load balancer plugin for HTTPlug
Installs: 3 039
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 6
Forks: 0
Open Issues: 0
Requires
- php: >=7.4
- php-http/client-common: >=2.0
- symfony/options-resolver: >=3.4
Requires (Dev)
- nyholm/psr7: ^1.0
- php-http/httplug: ^2.0
- php-http/mock-client: *
- ramsey/coding-standard: ^2.0
- symfony/phpunit-bridge: >=6.0
README
You might have found yourself in strange situation where instead of people using load balancer, they supply you list of hosts you should try to call. They also don't like it when you pick one of them and use that, instead of going through trouble of doing distribution on client side.
If you want to go through this trouble, you can use this HTTPlug plugin. It picks one of the hosts randomly at beginning and then keeps using it (sticky session), until there is a server or network error - in that case host that's being used is swapped for something else from the list. This ensures same host is never used twice in a row in case you use some retry mechanism.
Install
Via Composer
composer require php-http/random-host-plugin
Usage
new \Http\Client\Common\Plugin\SetRandomHostPlugin( $psr17Factory, ['hosts' => ['https://host1.example','https://host2.example']], );
Licensing
MIT license. Please see License File for more information.