DWQA QuestionsCategory: Artificial IntelligenceThinkPHP uses queues to generate large CSV files
taihao asked 4 days ago

ThinkPHP uses queues to generate large CSV filesExcuse me?If you use the command to generate a large CSV filePaging query method has been used for query dataNow there’s a problem. I don’t know if the memory will overflow in this way?Export memory with queue command_ Limit and Max_ execution_ Does the time parameter matter?,If you pay attention to memory consumption, you can choose to use the cursor to check one line at a time and then write to the file. This performance should be the best. In addition, for writing to the file, you should avoid using it directlyfile_put_contents。When running on the command linedefaultmax_execution_timeIs 0, but youYou can override this settingmemory_limitOr by PHP Ini configuration restrictions.If you just want to set these parameters temporarily, you can use PHP-dParameters, like thisphp -dmemory_limit=2G -dmax_execution_time=10

1 Answers
Unique answered 4 days ago

If you pay attention to memory consumption, you can choose to use the cursor to check one line at a time and then write to the file. This performance should be the best. In addition, for writing to the file, you should avoid using it directlyfile_put_contents。When running on the command linedefaultmax_execution_timeIs 0, but youYou can override this settingmemory_limitOr by PHP Ini configuration restrictions.If you just want to set these parameters temporarily, you can use PHP-dParameters, like thisphp -dmemory_limit=2G -dmax_execution_time=10

taihao replied 4 days ago

Excuse me, will the memory overflow when I generate Excel files in this queue?

Unique replied 4 days ago

You can provide the code or use it in the codememory_get_usageandmemory_get_peak_usageMethod to collect memory usage information for judgment.