IT. Expert System.

PHP

Sets a client-side timeout for this query


MongoCursor::timeout

(PECL mongo >=1.0.3)

MongoCursor::timeoutSets a client-side timeout for this query

Description

public MongoCursor MongoCursor::timeout ( int $ms )

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:

<?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!";
    }
}

?>

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.

Parameters

ms

The number of milliseconds for the cursor to wait for a response. By default, the cursor will wait forever.

Return Values

This cursor.

Examples

Example #1 MongoCursor::timeout() example

A query where the cursor waits for one second for a response.

<?php

$cursor 
$collection->find()->timeout(1000);

try {
  foreach (
$cursor as $value) {
    
print_r($value);
  }
}
catch(
MongoCursorTimeoutException $e) {
  echo 
"query took too long!";
}

?>

Errors/Exceptions

Causes methods that fetch results to throw MongoCursorTimeoutExceptions if the query takes longer than the number of milliseconds specified.



Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 408 / 158735386. Delta: 0.03037 с