Skip to content

Instantly share code, notes, and snippets.

@markomafs
Created November 19, 2015 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markomafs/5d892d06d6670909f9b4 to your computer and use it in GitHub Desktop.
Save markomafs/5d892d06d6670909f9b4 to your computer and use it in GitHub Desktop.
How to Resolve WeightLoadBalance into Php Application
<?php
class Factory {
const W = 'W';
const LOAD_BALANCE_W = 'BALANCE_W';
const X = 'X';
const LOAD_BALANCE_X = 'BALANCE_X';
const Y = 'Y';
const LOAD_BALANCE_Y = 'BALANCE_Y';
const Z = 'Z';
const LOAD_BALANCE_Z = 'BALANCE_Z';
protected $_config = array (
// enable disable flag
self::W => 1,
self::X => 1,
self::Y => 1,
self::Z => 1,
// weighted percentage
self::LOAD_BALANCE_W => 5,
self::LOAD_BALANCE_X => 15,
self::LOAD_BALANCE_Y => 25,
self::LOAD_BALANCE_Z => 55,
);
public function handleAdapter()
{
$isWActive = (boolean)$this->_config[self::W];
$isXActive = (boolean)$this->_config[self::X];
$isYActive = (boolean)$this->_config[self::Y];
$isZActive = (boolean)$this->_config[self::Z];
$WPercentage = (int)$this->_config[self::LOAD_BALANCE_W];
$XPercentage = (int)$this->_config[self::LOAD_BALANCE_X];
$YPercentage = (int)$this->_config[self::LOAD_BALANCE_Y];
$ZPercentage = (int)$this->_config[self::LOAD_BALANCE_Z];
return self::W;
}
}
$i=100;
while ($i--) {
echo (new Factory())->handleAdapter() .PHP_EOL;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment