Created
November 19, 2015 18:04
-
-
Save markomafs/5d892d06d6670909f9b4 to your computer and use it in GitHub Desktop.
How to Resolve WeightLoadBalance into Php Application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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