Is there any way PHP can export 100,000 records to Excel once?
Reply content:
Is there any way PHP can export 100,000 records to Excel once?
Use Mysqli_use_result non-buffered query, stream, from MySQL to get, in the Loop Fetch_row fputcsv ($fp, $row) write data to the file, and then provide to the user to download. The code logic is probably as follows:
Query ($sql, Mysqli_use_result); unbuffered query while ($row = $result->fetch_row ()) {//read-through (unbuffered query) fputcsv ($fp, $row);//write to}fclose ($FP); header (' Content-disposition:attachment; Filename= "File.csv"); ReadFile (' file.csv ');
You can download it properly.
Phpexcel supports row caching, and a file cache is set.
https://github.com/PHPOffice/...
Batch write, a one-time export of 10w records and write the situation is prone to timeouts, we recommend that the performance of the server and the size of the content of the test