(PECL mongo >=1.2.11)

MongoCursor::awaitDataSets whether this cursor will wait for a while for a tailable cursor to return more data


public MongoCursor MongoCursor::awaitData ([ bool $wait = true ] )

This method is to be used with tailable cursors. If we are at the end of the data, block for a while rather than returning no data. After a timeout period, we do return as normal.

Список параметров


If the cursor should wait for more data to become available.

Возвращаемые значения

Returns this cursor.


Throws MongoCursorException if this cursor has started iterating.


Пример #1 MongoCursor::awaitData() example

In this example we tail the "oplog" and instead of sleeping during every iteration, we set the MongoCursor::awaitData() option. MongoCursor::hasNext() will now block until there is more data available.

= new MongoClient'mongodb://localhost:13000', array( 'replSet' => 'seta' ) );
$c $m->local->selectCollection'' );
$cursor $c->find( array( 'ns' => 'demo.article''op' => 'i' ) );
$cursor->tailabletrue );
$cursor->awaitDatatrue );

while (
true) {
    if (!
$cursor->hasNext()) {
// we've read all the results, exit
if ($cursor->dead()) {
    } else {
var_dump$cursor->getNext() );

Смотрите также

MongoDB core docs on » tailable cursors.


404 Not Found

404 Not Found


    Поддержать сайт на родительском проекте КГБ