您的位置:首页 > 大数据

php大数据量查询时内存持续增长问题

2016-05-26 19:14 162 查看
php进行数据库查询时会默认使用Buffer。当查询数据量较大时,需要使用Unbuffered Queries。具体见加粗参数。

/Create the connection
$con = mysqli_connect("127.0.01","root","123456",'test', 3306) or die("Some error occurred during connection " . mysqli_error($con));

// Write query
$strSQL = "SELECT id,report_id FROM pressure_test limit 100000";

// Execute the query.
//$query = mysqli_query($con, $strSQL);
$query = mysqli_query($con, $strSQL, MYSQLI_USE_RESULT); //需要添加MYSQLI_USE_RESULT

echo (floor( memory_get_usage() / 1024) ).' kb'. "\n";

// loop over the rows, outputting them
/* while ($row = $query->fetch_assoc())
{
echo (floor( memory_get_usage() / 1024) ).' kb'. "\n";
//fputcsv($output, $row);
} */

$row ='';
$i= 10000;
while($row = mysqli_fetch_assoc($query))
{
if($i == 0){
echo (floor( memory_get_usage() / 1024) ).' kb in while'. "\n";
$i = 10000;
}
unset($row);
$i--;
}
echo (floor( memory_get_usage() / 1024) ).' kb after while'. "\n";
// Close the connection
mysqli_close($con);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  p php 内存 buffer