Created
February 27, 2014 02:56
-
-
Save alexis-gruet-deel/9243496 to your computer and use it in GitHub Desktop.
Round Robin Algorithm PHP
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
/** | |
for( $a=1; $a<20; $a++ ) { | |
echo '----------------------' . PHP_EOL; | |
echo 'PROJECT_ID :: ' . $a . PHP_EOL; | |
$last = $c[ 'predis' ]->get( 'round-robin-dispatch' ); | |
$i = $j = -1; | |
$n = count( $array ); | |
if( isset( $last )) { | |
$i = $j = $last; | |
} | |
do { | |
$j = ( $j + 1 ) % $n; | |
if( isset( $array[$j] ) ) { | |
$i = $j; | |
$c[ 'predis' ]->set( 'round-robin-dispatch', $i ); | |
$current = $array[ $i ]; | |
} | |
} while ( $j != $i ); | |
echo 'Will be sent to :: ' . $current . PHP_EOL; | |
echo 'Will be sent to :: aviva' . PHP_EOL; | |
sleep( 2 ); | |
} | |
echo PHP_EOL; **/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment