|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70509 Method MongoCursor::maxTimeMS doesn't always throw timeout exception
Submitted: 2015-09-16 10:24 UTC Modified: -
From: fabrice at workdigital dot co dot uk Assigned:
Status: Open Package: mongo (PECL)
PHP Version: 5.6.13 OS: Debian
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
2 + 44 = ?
Subscribe to this entry?

 [2015-09-16 10:24 UTC] fabrice at workdigital dot co dot uk
Contrary as what the documentation says, MongoCursor::maxTimeMS() doesn't always throws MongoExecutionTimeoutException, it doesn't work this way when you use next() on the cursor.
See the working script examples for details!

Test script:
// Currently throwing exception (fine!)

    // Any slightly big collection should do here
    $cursor = $mongo->test->test->find(['i' => 9999999])->maxTimeMS(1);
    // $doc = iterator_to_array($cursor);
    foreach ($cursor as $item) {

// Doesn't throw an exception (bad!)
    $doc = $mongo->test->test->find(['i' => 9999999])->maxTimeMS(1)->next();
    // Will display:
    // array(2) {
    // '$err' =>
    // string(29) "operation exceeded time limit"
    //  'code' =>
    // int(50)
    // }


Add a Patch

Pull Requests

Add a Pull Request

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Nov 29 03:01:27 2023 UTC