php-doc-en/reference/mongo/mongocursor/maxtimems.xml
2014-09-23 12:08:23 +00:00

119 lines
3.3 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="mongocursor.maxtimems" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>MongoCursor::maxTimeMS</refname>
<refpurpose>Sets a server-side timeout for this query</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <type>MongoCursor</type><methodname>MongoCursor::maxTimeMS</methodname>
<methodparam><type>int</type><parameter>ms</parameter></methodparam>
</methodsynopsis>
<para>
Specifies a cumulative time limit in milliseconds to be allowed by the server
for processing operations on the cursor.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
<varlistentry>
<term>
<parameter>ms</parameter>
</term>
<listitem>
<para>
Specifies a cumulative time limit in milliseconds to be allowed by the
server for processing operations on the cursor.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
This cursor.
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
Throws <classname>MongoCursorException</classname> if this cursor has started
iterating.
</para>
<para>
Causes methods that fetch results to throw a
<classname>MongoExecutionTimeoutException</classname> if the query takes
longer than the specified number of milliseconds in processing time.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><methodname>MongoCursor::maxTimeMS</methodname> example</title>
<para>
In the following example, the server will abort the query if the cursor
requires more than two seconds in processing time to return its results.
</para>
<programlisting role="php">
<![CDATA[
<?php
$cursor = $collection->find();
$cursor->maxTimeMS(2000);
try {
$results = iterator_to_array($cursor);
} catch (MongoExecutionTimeoutException $e) {
echo "query took too long!";
}
?>
]]>
</programlisting>
</example>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<warning>
<para>
Unlike <methodname>MongoCursor::timeout</methodname>, which specifies a
client-side timeout, <methodname>MongoCursor::maxTimeMS</methodname> can be
used to cause the MongoDB server to abort long-running queries. This
timeout is cumulative for the lifetime of the cursor (i.e. each batch will
contribute to this time limit). The timeout only considers processing time;
idle time is not considered.
</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
-->