MongoCursor::awaitData

(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::awaitData ([ bool $wait = TRUE ] ) : MongoCursor

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.

参数

wait

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

返回值

Returns this cursor.

错误/异常

Throws MongoCursorException if this cursor has started iterating.

范例

Example #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.

<?php
$m 
= new MongoClient'mongodb://localhost:13000', array( 'replSet' => 'seta' ) );
$c $m->local->selectCollection'oplog.rs' );
$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()) {
            break;
        }
    } else {
        
var_dump$cursor->getNext() );
    }
}
?>

参见

MongoDB core docs on » tailable cursors.

相关文章
php enchant 函数 will return a list of values if any of those pre conditions are not metphp snmp 函数 return the method how the snmp values will be returnedphp yaz 函数 sets one or more options for connectionphp imagickdraw sets the fill rule to use while drawing polygonsphp mongocursor sets whether this cursor will wait for a while for a tailable cursor to return more dataphp mongocursor advances the cursor to the next result and returns that resultphp mongocursor checks if there are any more elements in this cursorphp mongocursor sets whether this cursor will timeoutphp mongocursor sets whether this query can be done on a secondary deprecated php mongocursor sets whether this cursor will be left open after fetching the last resultsphp phar returns whether phar has global meta dataphp sdo das relational 函数 executes an sql query passed as a prepared statement with a list of values to substitute for placeholders and return the results as a normalised data graphphp sdo 函数 return the name of the type for a data objectphp solrquery whether or not to return raw charactersphp solrquery sets the maximum number of terms to returnphp spldoublylinkedlist check whether the doubly linked list contains more nodesphp splfixedarray check whether the array contains more elementsphp svmmodel return class probabilities for previous unseen dataphp more details functions and statements which will spread the tainted mark of a tainted stringphp more details functions and statements which will check tainted string
关注编程学问公众号