Location: PHPKode > projects > MongoDB PHP Driver > mongodb-mongo-php-driver-a593f23/tests/rs.php
<?php

$m = new Mongo("mongodb://localhost:27017", array("replicaSet" => true));

$c = $m->foo->bar;

while (true) {
  echo "finding... ";
  $cursor = $c->find();

  try {
      $cursor->getNext();
  }
  catch (Exception $e) {
      echo $e->getMessage()." ";
  }
  $info1 = $cursor->info();
  if ($info1['server']) {
      echo $info1['server']." ";
  }
  echo "$m\n";

  try {
      echo "reading... ";
      $cursor = $c->find()->slaveOkay();
      $cursor->next();
      $info2 = $cursor->info();
      echo $info2['server'];
  }
  catch (Exception $e) {
      echo $e->getMessage()." ";
  }
  echo "\n";

  //  var_dump($m->getHosts());

  sleep(1);
}

?>
Return current item: MongoDB PHP Driver