略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: MongoCursor::immortal

2024-12-23

MongoCursor::immortal

(PECL mongo >=1.0.1)

MongoCursor::immortalSets whether this cursor will timeout

说明

public MongoCursor::immortal ([ bool $liveForever = TRUE ] ) : MongoCursor

After remaining idle on the server for some amount of time, cursors, by default, "die." This is generally the behavior one wants. The database cleans up a cursor once all of its results have been sent to the client, but if the client doesn't request all of the results, the cursor will languish there, taking up resources. Thus, after a few minutes, the cursor "times out" and the database assumes the client has gotten everything it needs and cleans up its the cursor's resources.

If, for some reason, you need a cursor to hang around for a long time, you can prevent the database from cleaning it up by using this method. However, if you make a cursor immortal, you need to iterate through all of its results (or at least until MongoCursor::dead() returns TRUE) or the cursor will hang around the database forever, taking up resources.

参数

liveForever

If the cursor should be immortal.

返回值

Returns this cursor.

错误/异常

Throws MongoCursorException if this cursor has started iterating.

add a note add a note

User Contributed Notes 2 notes

up
1
fastest963 at gmail dot com
5 years ago
Calling immortal(false), in order to remove the NO_TIMEOUT flag from the cursor, seems to crash with "Fatal error: Exception thrown without a stack frame in Unknown on line 0". I'm running PHP 5.2.17 and MongoDB driver 1.1.4.
up
1
iknox {at} info.com
7 years ago
Note:: There there is an important distinction between timeout and immortal!
Timeout indicates the time to wait on the _client_ side while immortal sets the cursor on the server side.

It is especially useful for large result sets in sharded environments.

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

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3