CRON命令与Yii [英] CRON command with Yii

查看:249
本文介绍了CRON命令与Yii的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码会自动创建一个sitemap.xml。我的网址如下所示: http://example.com/sitemap

I have a code that will automatic create a sitemap.xml . My Url look like this : http://example.com/sitemap

但现在我想让它每分钟自动运行(只是测试)。我尝试了两种方式,但都没有工作:

But now I want it to automatic run every minutes (just test) . I tried 2 way but none of them work :

首先是通过URL调用,例如:

first is call through URL ,ex:

*/1 * * * * wget http://example.com/sitemap

*/5 * * * * curl http://example.com/check

第二个是调用throught php文件,我使用Yii,所以我不知道.php文件是什么?是这个控制器文件还是别的什么?

second is call throught php file , I'm using Yii so i'm not sure what the file .php is ? is this controller file or something else?

*/1 * * * * /usr/bin/php /home/domains/public_html/protected/modules/homepage/controller/HomepageController.php

我的Sitemap操作的代码位于HomepageController.php

my Sitemap action's code inside HomepageController.php

推荐答案

使用 console命令用于运行CRON调用。例如,使用以下代码创建 SitemapCommand.php (将它放在 protected / command / 中):

Use console command for running CRON calls. For example, create SitemapCommand.php (place it in protected/command/) with following code:

class SitemapCommand extends CConsoleCommand
{
    public function actionGenerate($debug=0)
    {
        #generating of sitemap
    }
}

crontab 文件:

*/1 * * * * /usr/bin/php /home/domains/public_html/protected/yiic.php sitemap generate

这篇关于CRON命令与Yii的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆