如果PDO::MYSQL_ATTR_USE_BUFFERED_QUERY
缓冲了查询结果,那么如何留下未完成的查询(循环中的大型结果集上的单PDOStatement->fetch()
)不会像筛子一样泄漏?
内存结果在超时之前与第一次迭代之后相同:
<?php
$db = new PDO($connstring, $user, $pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
$i = 0;
$s = $db->prepare('SELECT * FROM table_with_tons_of_rows');
$s->execute();
var_dump($s->fetchAll());
var_dump([memory_get_usage(), memory_get_usage(true)]);
do {
$s = $db->prepare('SELECT * FROM table_with_tons_of_rows');
$s->execute();
$s->fetch();
var_dump([memory_get_usage(), memory_get_usage(true), $i++]);
} while (true);
当语句上的引用数量达到0时,PHP会自动转储缓冲区吗?