Yii and cron jobs(Yii 和 cron 工作)
问题描述
我创建了一个需要每个月运行的 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.hourly
和 etc/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. :)
这篇关于Yii 和 cron 工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Yii 和 cron 工作


基础教程推荐
- PHP 守护进程/worker 环境 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- HTTP 与 FTP 上传 2021-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01