Skip to content

Instantly share code, notes, and snippets.

@alexis-gruet-deel
Created February 27, 2014 02:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alexis-gruet-deel/9243496 to your computer and use it in GitHub Desktop.
Save alexis-gruet-deel/9243496 to your computer and use it in GitHub Desktop.
Round Robin Algorithm PHP
/**
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