diff --git a/reference/mongo/mongocursor/timeout.xml b/reference/mongo/mongocursor/timeout.xml index a4a3c01511..be3df75dcc 100644 --- a/reference/mongo/mongocursor/timeout.xml +++ b/reference/mongo/mongocursor/timeout.xml @@ -13,6 +13,42 @@ public MongoCursorMongoCursor::timeout intms + + 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: + +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!"; + } +} + +?> +]]> + + + + 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. + diff --git a/reference/mongo/mongocursortimeoutexception.xml b/reference/mongo/mongocursortimeoutexception.xml new file mode 100644 index 0000000000..0299e6f0e2 --- /dev/null +++ b/reference/mongo/mongocursortimeoutexception.xml @@ -0,0 +1,66 @@ + + + + + + The MongoCursorTimeoutException class + MongoCursorTimeoutException + + + + +
+ &reftitle.intro; + + Caused by a query timing out. At the moment, the only way a query will not + wait indefinitely for a database response is if + MongoCursor::timeout is called on the cursor. + +
+ + +
+ &reftitle.classsynopsis; + + + + MongoCursorTimeoutException + + + + + extends + MongoCursorException + + + + + + + +
+ +
+ +
+ + diff --git a/reference/mongo/versions.xml b/reference/mongo/versions.xml index bbc2a9d47e..94dbdefc14 100644 --- a/reference/mongo/versions.xml +++ b/reference/mongo/versions.xml @@ -10,6 +10,7 @@ + @@ -22,6 +23,7 @@ + @@ -43,6 +45,7 @@ +