gpt4 book ai didi

php - Zend_Db 和无缓冲查询

转载 作者:行者123 更新时间:2023-11-29 14:24:06 27 4
gpt4 key购买 nike

我有一个长时间运行的查询,我尝试通过无缓冲的 pdo 语句来获取该查询(请参阅接下来的代码)。但是,当我“执行”无缓冲的查询,或者执行“fetchAll”时,计时(另见下文)并没有真正改变太多......我的想法是,无缓冲只是执行查询并给我一个光标?

get_db 函数返回一个 Zend_Db 对象。

  l('Start 1');

$sql = get_db('ATO')->select()
... Big query...
->assemble();

l('Assembled');

get_db('APNS')->query($sql)->fetchAll();

l('All fetched... Going again!');

$PDOStatement = get_db('ATO')->getConnection()
->prepare($sql,
array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false));

l('prepared');

if ( $PDOStatement->execute() === false ) {
l(':(');
exit(1);
}

l('fetching');

while ( ($PDOrow = $PDOStatement->fetch()) !== false ) {
}

l ('all done');

function l($t) {
static $start = null;
if ( $start === null ) {
$start = microtime(true);
}
echo sprintf("[%0.5f] %s\n", microtime(true) - $start, $t);
}

时间安排:

[0.00000] Start 1
[0.02262] Assembled
[214.69091] All fetched... Going again!
[214.69105] prepared
[417.01584] fetching
[420.55217] all done

正如您所看到的,获取所有变量和未缓冲变量几乎没有区别。

我在这里可能做错了什么?

谢谢!

最佳答案

您错了,因为您尝试使用无缓冲查询来加速。

  1. 缓冲查询将所有结果提取到 PHP 内存中。
  2. 未缓冲的结果位于服务器上,直到被提取为止。

每种方式都有自己的优点和缺点,但与时间的关系较弱。

阅读手册 Buffered and Unbuffered queries

关于php - Zend_Db 和无缓冲查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11312187/

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