Yii Framework Forum

Yii2 cronjob using


(alren) #1

Hi ,
I use basic template and I want to run anyone action with crontab. I installed yii2-scheduling extension.
i created schedule.php file to /var/www/html/basic/config/ as like this.

<?php

$schedule->exec('touch /var/www/html/a.txt')->everyMinute();
 
?>

I try to create a.txt file every minutes at this command.
After this , I added this line int /etc/crontab

* * * * * php /var/www/html/basic/yii schedule/run --scheduleFile=/var/www/html/basic/config/schedule.php
and I wait it’s work. But not work.

If I run this command on command line “php /var/www/html/basic/yii schedule/run” it is works and a.txt file created. But crontab not work.


(Mehdi Achour) #2

When adding cronjobs to /etc/crontab, you must specify the user field.

It should read:

* * * * *  USER php /var/www/html/basic/yii schedule/run --scheduleFile=/var/www/html/basic/config/schedule.php

(alren) #3

Thank you very much.