我有一个脚本,当放在计时器上时,它会逐渐变慢。这相当简单,因为它所做的只是读取一行,检查它然后将其添加到数据库中,然后继续下一行。
这是它的输出逐渐变得更糟:
Record: #1,001 Memory: 1,355,360kb taking 1.84s
Record: #1,001 Memory: 1,355,360kb taking 1.84s
Record: #2,002 Memory: 1,355,192kb taking 2.12s
Record: #3,003 Memory: 1,355,192kb taking 2.39s
Record: #4,004 Memory: 1,355,192kb taking 2.65s
Record: #5,005 Memory: 1,355,200kb taking 2.94s
Record: #6,006 Memory: 1,355,376kb taking 3.28s
Record: #7,007 Memory: 1,355,176kb taking 3.56s
Record: #8,008 Memory: 1,355,408kb taking 3.81s
Record: #9,009 Memory: 1,355,464kb taking 4.07s
Record: #10,010 Memory: 1,355,392kb taking 4.32s
Record: #11,011 Memory: 1,355,352kb taking 4.63s
Record: #12,012 Memory: 1,355,376kb taking 4.90s
Record: #13,013 Memory: 1,355,200kb taking 5.14s
Record: #14,014 Memory: 1,355,184kb taking 5.43s
Record: #15,015 Memory: 1,355,344kb taking 5.72s
不幸的是,该文件大约为 20gb,所以当整个文件以增加的速度读取时,我可能已经死了。代码(主要)在下面,但我怀疑它与 fgets() 有关,但我不确定是什么。
$handle = fopen ($import_file, 'r');
while ($line = fgets ($handle))
{
$data = json_decode ($line);
save_record ($data, $line);
}
提前致谢!
编辑:
注释掉 'save_record ($data, $line);' 似乎什么都不做。