【发布时间】:2013-02-27 15:58:55
【问题描述】:
$name = 'mybigfile.csv';
$fp = fopen(...);
while($row = mysql_fetch_assoc($sql_result)) {
fputcsv($fp, $row);
}
fclose($fp);
// send the correct headers
header("Content-Type: application/csv etc ....");
header("Content-Length: " . filesize($name));
// dump the file and stop the script
readfile($name);
exit;
这种方法效果很好,但有些文件很大,所以过程很慢......我在想 - 也许我可以避免先创建文件然后写入数据然后读取数据的过程并输出.... .i.e.如果我在 while 循环之前发送标头并在 while 循环中回显行(而不是将其写在一行中)或类似的东西。这会是更有效的过程吗?你会建议我如何改进这个过程?谢谢
【问题讨论】: