Is there any way in PHP to export 100,000 records to Excel at one time?
Is there any way in PHP to export 100,000 records to Excel at one time?
Use MYSQLI_USE_RESULT unbuffered query, a long stream, get it from MySQL one by one, in the loop fetch_row, fputcsv($fp, $row) writes data to the file one by one, and then provides it to the user for download. The code logic is roughly as follows:
query($sql, MYSQLI_USE_RESULT); //无缓冲查询 while ($row = $result->fetch_row()) { //逐条读取(无缓冲查询) fputcsv($fp, $row); //逐条写入 } fclose($fp); header('Content-Disposition: attachment; filename="file.csv"'); readfile('file.csv');
You are normal Just download it.
PHPExcel supports line caching, just set up a file cache.
https://github.com/PHPOffice/...
Writing in batches, exporting 100,000 records at one time and writing is prone to timeout. It is recommended to test based on the performance of the server and the size of the content.