1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 331219 $ -->
<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>MongoCursor::$timeout</varname> milliseconds.
</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.
</para>
</warning>
</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
-->
|