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 工作
基础教程推荐
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何替换eregi() 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
