php-doc-en/reference/mongo/mongocursor/timeout.xml
Jeremy Mikola 9f0e1e36a3 Documentation for MongoCursorInterface
This interface extends Iterator and is implemented internally by MongoCursor and MongoCommandCursor. In addition to the interface methods, "see also" links were added on the implemented methods to point back to the interface documentation (as we did for Iterator methods).

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


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@335760 c90b9560-bf6c-de11-be94-00142212c4b1
2015-01-15 21:10:35 +00:00

133 lines
3.6 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="mongocursor.timeout" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>MongoCursor::timeout</refname>
<refpurpose>Sets a client-side timeout for this query</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <type>MongoCursor</type><methodname>MongoCursor::timeout</methodname>
<methodparam><type>int</type><parameter>ms</parameter></methodparam>
</methodsynopsis>
<para>
A timeout can be set at any time and will affect subsequent queries on the
cursor, including fetching more results from the database.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
<varlistentry>
<term>
<parameter>ms</parameter>
</term>
<listitem>
<para>
The number of milliseconds for the cursor to wait for a response. Use
<literal>-1</literal> to wait forever. By default, the cursor will wait
<varname>30000</varname> milliseconds (30 seconds).
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
This cursor.
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
Causes methods that fetch results to throw a
<classname>MongoCursorTimeoutException</classname> if the query takes longer
than the specified number of milliseconds.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><function>MongoCursor::timeout</function> example</title>
<para>
In the following example, the driver will wait forever for the initial
database response, and then wait 100ms for subsequent responses.
</para>
<programlisting role="php">
<![CDATA[
<?php
$cursor = $collection->find();
$cursor->timeout(-1);
/* $cursor->hasNext() executes the query. An infinite timeout has been set, so
* the driver will wait as long as necessary for a response.
*/
while ($cursor->hasNext()) {
$cursor->timeout(100);
/* A timeout has now been set, so if the cursor needs to get more results
* from the database, it will only wait 100ms for a response.
*/
try {
print_r($cursor->getNext());
} catch (MongoCursorTimeoutException $e) {
echo "query took too long!";
}
}
?>
]]>
</programlisting>
</example>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<warning>
<para>
This does not cause the MongoDB server to cancel long-running operations;
it only instructs the driver to stop waiting for a response and throw a
<classname>MongoCursorTimeoutException</classname> after a set time.
If you need to specify a server-side timeout for a query, consider using
<methodname>MongoCursor::maxTimeMS</methodname>.
</para>
</warning>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><methodname>MongoCursorInterface::timeout</methodname></member>
<member>The <literal>socketTimeoutMS</literal> option for <function>MongoClient::__construct</function></member>
</simplelist>
</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
-->