I have a web form that uploads a image. While the user uploads the image, i would like to user to be able to carry on to browse my website while at the background, the image gets resize/converted/write to db. Uploading a image can take a long time and I would like to improve the user interaction with my yii website so user do not have to wait.
I thought aftersave() was a function that I can achieve this. but the user still have to wait for all the functions in aftersave() to complete.
So I guess I would need to write another model call ‘sync’ that will cron every 1 min in the background to ‘catch’ whether there is a new image uploaded.
You can also use the log for user activities and then check which actions or processes that can be carried out in background and use cronjob for them to complete the tasks initiated by the user.
Example
User Clicks on Image Load
User Selects The Image
User Click on Upload - Do in Background
User Click on Friends List
User Send a Request for New Friends - Do in Background
I will stick to cron. Maybe in the next version of yii, there will be a build-in ‘function cronTask()’ for each model so we can populate the scripts that needs to be cron.
Then we can cron a ‘yiicron.php’ which will call the ‘function cronTask()’ each model? Just an idea.
Good advice below to run the friend request in the background as well!