Skip to content

Instantly share code, notes, and snippets.

@jmikola
Created May 3, 2013 16:38
Show Gist options
  • Save jmikola/5510920 to your computer and use it in GitHub Desktop.
Save jmikola/5510920 to your computer and use it in GitHub Desktop.
Testing awaitData and tailable cursors against mongod
$m = new MongoClient();
$m->test->foo->drop();
$m->test->createCollection('foo', ['capped' => true, 'size' => 67108864]);
$c = $m->test->foo;
$c->insert(['x' => 1]);
$cursor = $c->find()->awaitData()->tailable();
while (1) {
if (!$cursor->hasNext()) {
if ($cursor->dead()) {
break;
}
// optionally sleep a few seconds before re-polling
continue;
}
var_dump($cursor->getNext());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment