php-doc-en/reference/mongo/mongocursor/awaitdata.xml
Jeremy Mikola 8a4640c71c Revise replica set language and MongoClient references
Replace master/slave terminology with primary/secondary
Change most Mongo class references to MongoClient
Enforce 80-char line widths and trim trailing whitespace
Add literal formatting within some paragraphs

https://jira.mongodb.org/browse/PHP-583


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@328496 c90b9560-bf6c-de11-be94-00142212c4b1
2012-11-26 03:07:28 +00:00

120 lines
3.2 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="mongocursor.awaitdata" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>MongoCursor::awaitData</refname>
<refpurpose>Sets whether this cursor will wait for a while for a tailable cursor to return more data</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <type>MongoCursor</type><methodname>MongoCursor::awaitData</methodname>
<methodparam choice="opt"><type>bool</type><parameter>wait</parameter><initializer>true</initializer></methodparam>
</methodsynopsis>
<para>
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.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term>
<parameter>wait</parameter>
</term>
<listitem>
<para>
If the cursor should wait for more data to become available.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns this cursor.
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
Throws <classname>MongoCursorException</classname> if this cursor has started iterating.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><function>MongoCursor::awaitData</function> example</title>
<para>
In this example we tail the "oplog" and instead of sleeping during every
iteration, we set the <function>MongoCursor::awaitData</function> option.
<function>MongoCursor::hasNext</function> will now block until there is
more data available.
</para>
<programlisting role="php">
<![CDATA[
<?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->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() );
}
}
?>
]]>
</programlisting>
</example>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
MongoDB core docs on <link xlink:href="&url.mongodb.dochub.tailable;">tailable cursors</link>.
</para>
<para>
<simplelist>
<member><function>MongoCursor::tailable</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->