gpt4 book ai didi

php - MongoDB - 为什么我应该使用游标而不是 iterator_to_array(在 PHP 中)

转载 作者:IT老高 更新时间:2023-10-28 13:11:44 26 4
gpt4 key购买 nike

mongo 类的 PHP 文档说 using a cursor而不是 iterator_to_array 更好。

为什么?我将从中获得什么好处/灵 active ?

最佳答案

使用 iterator_to_array() 使您的驱动程序一次将所有结果加载到内存中,并且您很容易耗尽内存。使用延迟加载的游标不会出现这种情况!

直接来自链接docs :

<?php

$cursor = $collection->find();
var_dump(iterator_to_array($cursor));

?>

...

Suppose that, in the example above, $collection was a 50GB collection. We certainly wouldn't want to load that into memory all at once, which is what a cursor is for: allowing the client to access the collection in dribs and drabs.

关于php - MongoDB - 为什么我应该使用游标而不是 iterator_to_array(在 PHP 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5060956/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com