jimboobrien
2/27/2014 - 2:56 AM

Round Robin Algorithm PHP

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; **/