Yii2 Batch Export


I have a large number of rows that I need to export in CSV but the problem is that it is so large that it’s timing out (I already increased the time out to the max) so I was wondering if there is any way to use batch to export my data without blocking the user.

For example, click in Export and would start the batch process but user can still navigate on the site and as soon batch is complete than it popups to save the CSV file.

Is that possible in Yii2? If not, do you have another suggestion of exporting such a large database?


  1. Do it as a background job. Either via queues such as rabbitmq or via cron.

  2. You can fetch data in packs and write in batches so memory won’t be used much.

Thanks for the reply. I do not understand much about cron and background process.

Do you have any link or component that would give me some more light?

Cron is a Linux/Mac thing that executes a command once in a while. A command can be anything and in case of Yii it’s console command: http://www.yiiframework.com/doc-2.0/guide-tutorial-console.html