(PECL mongo >=1.2.11)
Sets 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.
Parameters:
wait
If the cursor should wait for more data to become available.
Returns:
Returns this cursor.
Exception:
Throws MongoCursorException if this cursor has started iterating.
Examples:
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <?php $c = $m ->local->selectCollection( 'oplog.rs' ); $cursor = $c ->find( array ( 'ns' => 'demo.article' , 'op' => 'i' ) ); $cursor ->tailable( true ); $cursor ->awaitData( true ); while (true) { if (! $cursor ->hasNext()) { // we've read all the results, exit if ( $cursor ->dead()) { break ; } } else { var_dump( $cursor ->getNext() ); } } ?> |
See also:
Please login to continue.