Laravel 中的 Cron 作业
我正在尝试为我已经创建的命令开发一个 cron 作业.我对 cron 工作完全陌生,所以我真的不知道它是如何工作的.
I am trying to develop a cron job for a command I have already created. I am completely new to cron jobs so I dont really know how it works.
在控制台中自己尝试该命令效果很好.我所需要的只是能够每 24 小时执行一次.我正在使用 Laravel 4,有人可以帮忙吗?
Trying the command by myself in the console works perfectly. All I need is to be able to execute it every 24 hours. I am using Laravel 4, can anyone help?
谢谢!
推荐答案
要以 root 身份创建 cron 作业,请编辑您的 cron 文件:
To create a cron job as root, edit your cron file:
[sudo] crontab -e
在最后添加一个新行,每一行都是一个cron作业:
Add a new line at the end, every line is a cron job:
25 10 * * * php /var/www/<siteName>/artisan <command:name> <parameters>
这将在每天上午 10:25 执行相同的命令.
This will execute the same command at 10:25AM everyday.
只要确保在最后一行之后保留一个空行.您可能还需要使用 php 客户端的完整路径:
Just make sure you keep a blank line after the last one. And you also might need to use the full path of your php client:
25 10 * * * /usr/local/bin/php /var/www/<siteName>/artisan <command:name> <parameters>
相关文章