mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-26 22:08:55 +00:00

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@293290 c90b9560-bf6c-de11-be94-00142212c4b1
133 lines
3.3 KiB
XML
133 lines
3.3 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. For example, to
|
|
wait forever for an initial response but timeout after 100 ms for subsequent
|
|
results, one could say:
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$cursor = $collection->find();
|
|
|
|
// $cursor->hasNext() executes the query. No timeout has been set, so the
|
|
// program will wait as long as necessary for a response.
|
|
|
|
while ($cursor->hasNext()) {
|
|
$cursor->timeout(100);
|
|
|
|
// now the timeout has been set, so if the cursor needs to get more results
|
|
// from the database, it will only wait 100 ms for the database's reply
|
|
|
|
try {
|
|
print_r($cursor->getNext());
|
|
}
|
|
catch(MongoCursorTimeoutException $e) {
|
|
echo "query took too long!";
|
|
}
|
|
}
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</para>
|
|
<para>
|
|
A timeout of 0 (or a negative number) will wait forever so it can be used to
|
|
reset the cursor if a timeout is no longer needed.
|
|
</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. By
|
|
default, the cursor will wait forever.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
This cursor.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<example>
|
|
<title><function>MongoCursor::timeout</function> example</title>
|
|
<para>
|
|
A query where the cursor waits for one second for a response.
|
|
</para>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$cursor = $collection->find()->timeout(1000);
|
|
|
|
try {
|
|
foreach ($cursor as $value) {
|
|
print_r($value);
|
|
}
|
|
}
|
|
catch(MongoCursorTimeoutException $e) {
|
|
echo "query took too long!";
|
|
}
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</refsect1>
|
|
|
|
<refsect1 role="errors">
|
|
&reftitle.errors;
|
|
<para>
|
|
Causes methods that fetch results to throw
|
|
<classname>MongoCursorTimeoutException</classname>s if the query takes longer
|
|
than the number of milliseconds specified.
|
|
</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
|
|
-->
|