Mysqli导致内存使用情况 [英] Mysqli results memory usage

查看:84
本文介绍了Mysqli导致内存使用情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么当内部指针通过循环前进时,此查询中的内存消耗会继续增加?如何使它更高效,更精简?

Why is the memory consumption in this query continuing to rise as the internal pointer progresses through loop? How to make this more efficient and lean?

$link = mysqli_connect(...);
$result = mysqli_query($link,$query); // 403,268 rows in result set
while ($row = mysqli_fetch_row($result)) 
{
    // print time, (get memory usage), -- row number
}
mysqli_free_result();
mysqli_close($link);
/*
06:55:25 (1240336) -- Run query
06:55:26 (39958736) -- Query finished
06:55:26 (39958784) -- Begin loop
06:55:26 (39960688) -- Row 0
06:55:26 (45240712) -- Row 10000
06:55:26 (50520712) -- Row 20000
06:55:26 (55800712) -- Row 30000
06:55:26 (61080712) -- Row 40000
06:55:26 (66360712) -- Row 50000
06:55:26 (71640712) -- Row 60000
06:55:26 (76920712) -- Row 70000
06:55:26 (82200712) -- Row 80000
06:55:26 (87480712) -- Row 90000
06:55:26 (92760712) -- Row 100000
06:55:26 (98040712) -- Row 110000
06:55:26 (103320712) -- Row 120000
06:55:26 (108600712) -- Row 130000
06:55:26 (113880712) -- Row 140000
06:55:26 (119160712) -- Row 150000
06:55:26 (124440712) -- Row 160000
06:55:26 (129720712) -- Row 170000
06:55:27 (135000712) -- Row 180000
06:55:27 (140280712) -- Row 190000
06:55:27 (145560712) -- Row 200000
06:55:27 (150840712) -- Row 210000
06:55:27 (156120712) -- Row 220000
06:55:27 (161400712) -- Row 230000
06:55:27 (166680712) -- Row 240000
06:55:27 (171960712) -- Row 250000
06:55:27 (177240712) -- Row 260000
06:55:27 (182520712) -- Row 270000
06:55:27 (187800712) -- Row 280000
06:55:27 (193080712) -- Row 290000
06:55:27 (198360712) -- Row 300000
06:55:27 (203640712) -- Row 310000
06:55:27 (208920712) -- Row 320000
06:55:27 (214200712) -- Row 330000
06:55:27 (219480712) -- Row 340000
06:55:27 (224760712) -- Row 350000
06:55:27 (230040712) -- Row 360000
06:55:27 (235320712) -- Row 370000
06:55:27 (240600712) -- Row 380000
06:55:27 (245880712) -- Row 390000
06:55:27 (251160712) -- Row 400000
06:55:27 (252884360) -- End loop
06:55:27 (1241264) -- Free */

推荐答案

AFAIK某些mysqli实现确实保留了与列的最大大小一样多的内存.因此,即使文本字段中有1Kb,它也会保留64k,而不是1.

AFAIK some of mysqli implementations do reserve as much memory as column's max size. So, even if you have 1Kb in the text field, it will reserve 64k, not 1.

我不太擅长,但是您可以尝试mysqli_unbuffered_query(如果有的话)

I'm not so good at it, but you can try mysqli_unbuffered_query (if there is any)

或者,作为最佳选择-仅选择特定页面上所需的行和列

Or, as the best choice - select only rows and columns that you need on the particular page

这篇关于Mysqli导致内存使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆