Yii 和 cron 工作

2022-01-04 00:00:00 cron crontab php yii

我创建了一个需要每个月运行的 Yii 命令.如果我转到受保护的文件夹并手动运行命令:

I have created a Yii command that needs to be run every month. If I go to my protected folder and run the command manually:

protected/yiic ganadores

它工作正常.我尝试将以下命令行添加到 etc/cron.hourlyetc/crontab 中,但没有成功:

It works fine. I have tried to add the following command line to etc/cron.hourly and etc/crontab with no success:

/usr/bin/php5/var/www/path/to/project/protected/yiic ganadores (etc/cron.hourly/ganadores)

/usr/bin/php5 /var/www/path/to/project/protected/yiic ganadores (etc/cron.hourly/ganadores)

0 0 1 * * root/usr/bin/php5/var/www/path/to/project/protected/yiic ganadores(etc/crontab)

0 0 1 * * root /usr/bin/php5 /var/www/path/to/project/protected/yiic ganadores (etc/crontab)

如果我手动运行 etc/cron.hourly 中的文件 ganadores,它也能正常工作.

If I run the file ganadores inside etc/cron.hourly manually, it's working also.

我在这里遗漏了什么?

终于解决了.我在 cron 行中有一些额外的空格.使用制表符代替空格,它开始工作..

Finally got it solved. I had some extra spaces in the cron line. Used tab instead spaces and it started working..

推荐答案

这就是我运行 Yii cron 作业的方式(在根 crontab 文件中):

This is how I run my Yii cron jobs (in the root crontab file):

45 23 * * * sudo -u www-data php /path/to/yii/app/protected/console.php mycommand

基本上只是常规的 crontab 语法,但我运行的是 console.php 而不是 yiic,并且我将用户设置为 Apache(www-data),因此我的脚本的权限是正确的.我不确定为什么你的不起作用,但希望看看我的会帮助你.:)

Basically just regular crontab syntax, but I am running console.php instead of yiic, and I am setting the user to Apache (www-data) so the permissions are correct for my script. I am not sure why yours isn't working, but hopefully looking at mine will help you out. :)

相关文章