如何在 yii 中设置 cron 作业 [英] How to set cron job in yii
问题描述
我是 yii 的新手.我正在做一个项目.
I am quite newbie to yii. I am working on a project.
我写了一个函数来向客户发送自动提醒
I have written a function to send automatic reminder to clients
说这个函数在 url :
say this function is at url :
http://somedomain.com/index.php/somecontroller/someaction
我想为这个 url 设置 cron.
I want to set the cron for this url.
一种方法是我应该写GET cron_job_url
.
但我不想将 url 用于我的 cron.我只想使用控制器和操作的物理路径.这可以用 yii
实现吗?
But I dont want to use the url for my cron.I only want to use physical path of the controller and action. Is this possible with yii
?
推荐答案
如果你想使用 cron 作业,我建议写一个 yiic
命令而不是调用 URL.它非常简单,您无需处理 URL 访问权限.
If you want to use a cron job, I'd suggest to write a yiic
command instead of calling a URL. It's very simple and you don't have to deal with URL access permissions.
创建一个从 CConsoleCommand
扩展的新类,并像在控制器中一样实现 run()
方法或某些操作.您可以在此处找到有关控制台命令的更多信息.您必须将命令保存到 protected/commands
目录,并且类名必须以 Command
结尾.
Create a new class that extends from CConsoleCommand
and implement either a run()
method or some actions as you would in a controller. You can find more information on console commands here. You have to save the command to the protected/commands
directory and the class name must end in Command
.
如果您的命令名为 DemoCommand
,那么您可以从 cron 作业中调用它作为 /path/to/your/webroot/protected/yiic demo
.
If your command is called DemoCommand
then you can call it from a cron job as /path/to/your/webroot/protected/yiic demo
.
这篇关于如何在 yii 中设置 cron 作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!