1

I implemented yii-crontab as instructed in http://www.yiiframework.com/extension/yii-crontab/ . I need to call a controller action automatically by implementing the cron job. But I am getting stuck on this because I am not getting the control flow to implement my requirement. Any helps are accepting..

anu
  • 458
  • 2
  • 13
  • 36
  • It would help you to add your progress. – alditis Dec 07 '12 at 18:08
  • 1
    In my experience it is better to use cron jobs separately from Yii. I could never run Yii cron jobs the way I wanted them, and ended up writing a lot more useless code. Simple `php` code is better IMO. – adamors Dec 07 '12 at 20:01

1 Answers1

0

You can write those controller actions in a controller in the folder named commands which will be located in the app root folder, and use a shell script to execute the cron.

commands is the CLI equivalent for what the controller folder is for web. Code structuring and everything else is same. So just copy your controllerfile from controllers to commands folder. Then write a php cron or a shell script to run the command at required intervals. More reference here

https://www.yiiframework.com/doc/guide/2.0/en/tutorial-console

Running a simple shell script as a cronjob

K3V
  • 282
  • 6
  • 17
  • 1
    You're forcing a click-through. I think it would be better if you were to show how to do it here in this Answer. – Scratte Sep 23 '20 at 18:50
  • @Scratte what do you mean by forcing a click through? I have specifically mentioned the solution. And then given them more reference. Probably you are not really familiar with the framework, but even without the reference, the solution is available in my answer for an even intermediate level programmer. – K3V Sep 25 '20 at 04:31
  • 1
    It could be just my impression, but I think a lot of beginners use Stack Overflow. – Scratte Sep 25 '20 at 08:55