python - How to solve the problem when the browser is half stuck when exporting excel with more than 10,000 items?
習慣沉默2017-06-14 10:49:44
0
13
2023
Business requirements sometimes require tens of thousands of items to be exported. Can I use python to process it?? It’s too stuck. What if I use python to process it?
Time-consuming server tasks like this should not be designed as Browser->Sync->Server; should be in the form of asynchronous tasks:
Browser: I want an Excel, please generate it for me first
Server: OK, the mission has started
Browser: Let me refresh it and see (you can use a long connection instead), it seems to be completed. Give me the URL (URL can be reflected in the task, no need to obtain it again), I want to download it
Use asynchronous or multi-process, the browser submits the task, prompting that the task is being processed, the background multi-process script slowly processes it, and when it is completed, it pushes a message to the browser to prompt the user that the export operation has been completed and can be downloaded. Browser push message: http://www.workerman.net/web-... Multi-process framework: http://doc3.workerman.net/ins...
More than 10,000 items are not a lot. You can use the third-party library
PHPExcel
. Or directly exportcsv
, function:fputcsv
.If you want to export, just export it directly to CVS mode.
You don’t need to export it all at once. Export in batches
Time-consuming server tasks like this should not be designed as
Browser->Sync->Server
;should be in the form of asynchronous tasks:
Browser: I want an Excel, please generate it for me first
Server: OK, the mission has started
Browser: Let me refresh it and see (you can use a long connection instead), it seems to be completed. Give me the URL (URL can be reflected in the task, no need to obtain it again), I want to download it
Server: http://domain.com/test.xlsx
Browser: Start download
Isn’t it enough to have more than 10,000 entries? How big is the file?
You can make the generation segmented... write 1000 items in 1000 items.
In addition, if php times out, you can change set_time_limit()
Asynchronous, all export operations should be made asynchronous
Written in paging, for example, refresh once every 1000 items
Use the script to run, php -f export.php
Use asynchronous or multi-process, the browser submits the task, prompting that the task is being processed, the background multi-process script slowly processes it, and when it is completed, it pushes a message to the browser to prompt the user that the export operation has been completed and can be downloaded.
Browser push message: http://www.workerman.net/web-...
Multi-process framework: http://doc3.workerman.net/ins...