Laravel big data exports how to optimize excel

laravel big data export cannot perform how to optimize

Feb.28,2021

cannot be executed? The code has bug?
big data when foreach plus reference


if exported to csv format, there will be no problem, just open a file, stream write data on it.
but if you are using phpexcel, each cell is a php object. Even if caching is enabled, if there is too much data, an error will be reported that there is not enough memory.


data is very large


you ask others to write a long text to make it clear, and finished may not solve your problem, what if your code has bug?
paste your code in segments and explain. Then take a screenshot of the error report and put it in the question first.


just as it happens, sg pushed me an article this morning.
PHP generates and downloads EXCEL files with a large amount of data in real time
which may help you a lot


this problem only uses a solution, which does not consider the efficiency of your sql and code execution. Csv format is not considered here, because many operators or other people who need data need it. Originally, there are nearly 70 fields in my export, so you know that when exporting a large amount of data, there will be two obvious problems: script execution time is long, memory consumption is much longer, it is very easy to 504 (not discussing nginx php-cgi configuration here), and it will take up a lot of cpu time cpu occupancy soars, another possible problem is that when there are multiple exports in parallel, it will eat up a lot of memory, affecting the online business. So you can use paging export, and then this paging can still process the output on the server. Another better solution is that the server outputs JSON client to export excel, paging and browser export can solve this problem very well. Recommend a js export plug-in sheetJs github https://github.com/SheetJS/js.


you can use yield;
it can be said that any amount of data can be executed, and there are many introductions in the community, which you can take a look at.


fetch the data by paging and append it to the file.


traverse the request interface to write to the cache and then export the excel.


No error is reported, but the data is very large. Finally, it directly fails to reflect
clipboard.png
directly splicing the data in the database

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e50602-45088.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e50602-45088.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?