MongoCursor::maxTimeMS

(PECL mongo >=1.5.0)
Sets a server-side timeout for this query
public MongoCursor MongoCursor::maxTimeMS ( int $ms )

Specifies a cumulative time limit in milliseconds to be allowed by the server for processing operations on the cursor.

Parameters:
ms

Specifies a cumulative time limit in milliseconds to be allowed by the server for processing operations on the cursor.

Returns:

This cursor.

Exception:

Throws MongoCursorException if this cursor has started iterating.

Causes methods that fetch results to throw a MongoExecutionTimeoutException if the query takes longer than the specified number of milliseconds in processing time.

Examples:
MongoCursor::maxTimeMS() example

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.

<?php

$cursor = $collection->find();
$cursor->maxTimeMS(2000);

try {
    $results = iterator_to_array($cursor);
} catch (MongoExecutionTimeoutException $e) {
    echo "query took too long!";
}

?>

doc_php
2016-02-24 16:20:43
Comments
Leave a Comment

Please login to continue.