Deprecated: Optional parameter $keys declared before required parameter $cms_id is implicitly treated as a required parameter in /home/www/dev/work/class/blog/CmsKey.php on line 75

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$title is deprecated in /home/www/dev/work/website/lvesu/class/controller/blog/php.php on line 28

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$outlink is deprecated in /home/www/dev/work/website/lvesu/template/blog/cms/php.manual.tpl on line 2

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$status is deprecated in /home/www/dev/work/website/lvesu/template/blog/index.head.php on line 2
PHP - Manual: MongoCursor::maxTimeMS - 互联网笔记

略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: MongoCursor::maxTimeMS

2025-05-19

MongoCursor::maxTimeMS

(PECL mongo >=1.5.0)

MongoCursor::maxTimeMSSets a server-side timeout for this query

说明

public MongoCursor::maxTimeMS ( int $ms ) : MongoCursor

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

参数

ms

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

返回值

This cursor.

错误/异常

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.

范例

Example #1 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!";
}

?>

注释

Warning

Unlike MongoCursor::timeout(), which specifies a client-side timeout, MongoCursor::maxTimeMS() can be used to cause the MongoDB server to abort long-running queries. This timeout is cumulative for the lifetime of the cursor (i.e. each batch will contribute to this time limit). The timeout only considers processing time; idle time is not considered.

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/mongocursor.maxtimems.php

冷却塔厂家 广告
中文GPT4.0无需注册 广告
北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3