I’m new to the forum and fairly new to Yii Framework even though I have been working on an application built with it for about a month and a half.
This application generates reports in CSV form or PDF form now I’ve tried reducing the time and efficiency of these reports but some of them are infinitely large and take about 5 min which isn’t nice.
I want to know if there is way of working with Yii’s framework and making the generation of the reports in a transparent way and than a notification is shown on the web application (on any page in the web application) with a download link with it.
Hope you have some answers or different suggestions for me.
Five minutes is pretty good for infinitely large reports
A solution that springs to mind would involve:
A database table and associated model to hold details of report requests with a status field and request timestamp. Statuses could be pending, processing, ready, (also, maybe failed or error).
A cron job running every minute, pulling a list of pending requests, changing their status to processing and adding a timestamp representing when the request was accepted.
The cron job would use a console command to process each request, generate the file and write it either to a directory using the table ID as the name, or in the table itself as binary data if the files aren’t too big. It would update the row status to ready and add a completion timestamp.
There are several ways you could notify the users about the state of their requests on each page. You’d probably want to create an action listing all of the active requests too though.
You’d need to add something into the cron job to clean up old records. Perhaps the record and associated file should be deleted 24 hours after generation. You’ll also want to clean up (or reattempt) records that were marked as processing but not completed within a certain amount of time.