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);
/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);
相关文章推荐
- 一个关于if else容易迷惑的问题
- Android之使用Http协议实现文件上传功能
- PHP5.2.*防止Hash冲突拒绝服务攻击的Patch
- 深入理解PHP之匿名函数
- JSP/PHP基于Ajax的分页功能实现
- 关于PHP通过PDO用中文条件查询MySQL的问题。
- 什么是设计模式
- PHP数据库长连接mysql_pconnect的细节
- Php Installing An Expansion
- rem : web app适配的秘密武器
- php7 读取php.ini[4]
- 两种方式登录FTP
- IE7降低内存和降低CPU的几个技巧
- 网马生成器 MS Internet Explorer XML Parsing Buffer Overflow Exploit (vista) 0day
- Ruby中的p和puts的使用区别浅析
- 如何高效的使用内存
- DOS下内存的配置
- PHP+Apache在Windows 9x下的安装和配置
- IIS 6 的 PHP 最佳配置方法