MongoCursor::tailable

(PECL mongo >=0.9.4)

MongoCursor::tailableSets whether this cursor will be left open after fetching the last results

说明

public MongoCursor::tailable ([ bool $tail = TRUE ] ) : MongoCursor

Mongo has a feature known as tailable cursors which are similar to the Unix "tail -f" command.

Tailable means cursor is not closed when the last data is retrieved. Rather, the cursor marks the final object's position. you can resume using the cursor later, from where it was located, if more data were received.

Like any "latent cursor", the cursor may become invalid at some point -- for example if that final object it references were deleted. Thus, you should be prepared to requery if the cursor is MongoCursor::dead().

参数

tail

If the cursor should be tailable.

返回值

Returns this cursor.

错误/异常

Throws MongoCursorException if this cursor has started iterating.

范例

Example #1 MongoCursor::tailable() example

<?php

$cursor 
$collection->find()->tailable();

$results = array();

while (
1) {
    if (!
$cursor->hasNext()) {
        
// we've read all the results, exit
        
if ($cursor->dead()) {
            break;
        }
        
// read all results so far, wait for more
        
sleep(10);
    }
    else {
        
$results[] = $cursor->getNext();
    }
}

?>

参见

MongoDB core docs on » tailable cursors.

相关文章
php evloop must be called after a forkphp gettext 函数 specify the character encoding in which the messages from the domain message catalog will be returnedphp gmagickdraw sets the fill color to be used for drawing filled objectsphp imagickdraw returns the shape to be used at the end of open subpaths when they are strokedphp intlcodepointbreakiterator get last code point passed over after advancing or receding the iteratorphp mongocursor sets whether this cursor will wait for a while for a tailable cursor to return more dataphp mongocursor sets whether this cursor will timeoutphp mongocursor gets information about the cursor s creation and iterationphp 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 mongocursor sets a client side timeout for this queryphp mongocursor checks if the cursor is reading a valid resultphp mongodb driver cursor checks if the cursor may have additional resultsphp reflectionparameter returns whether parameter must be callablephp soapserver sets the object which will be used to handle soap requestsphp solrquery returns the list of fields that will be returned in the responsephp solrquery returns whether or not morelikethis results should be enabledphp solrquery returns whether or not the query will be boosted by the interesting term relevancephp solrquery sets the frequency below which terms will be ignored in the source docsphp swftextfield adds characters to a font that will be available within a textfield
关注编程学问公众号