Laravel 中的 Cron 作业
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16374513/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cron Job in Laravel
提问by Oliver Hoffman
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.
我正在尝试为我已经创建的命令开发一个 cron 作业。我对 cron 工作完全陌生,所以我真的不知道它是如何工作的。
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?
在控制台中自己尝试该命令效果很好。我所需要的只是能够每 24 小时执行一次。我正在使用 Laravel 4,有人可以帮忙吗?
Thanks!
谢谢!
回答by Antonio Carlos Ribeiro
To create a cron job as root, edit your cron file:
要以 root 身份创建 cron 作业,请编辑您的 cron 文件:
[sudo] crontab -e
Add a new line at the end, every line is a cron job:
在最后添加一个新行,每一行都是一个 cron 作业:
25 10 * * * php /var/www/<siteName>/artisan <command:name> <parameters>
This will execute the same command at 10:25AM everyday.
这将在每天上午 10:25 执行相同的命令。
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:
只要确保在最后一行之后保留一个空行。您可能还需要使用 php 客户端的完整路径:
25 10 * * * /usr/local/bin/php /var/www/<siteName>/artisan <command:name> <parameters>
回答by Luis Dalmolin
You could register your cron job like this:
您可以像这样注册您的 cron 作业:
php /path/to/your/laravel/project/artisan your-custom-command
回答by aebersold
See my answer on this question, my example is for L3 but should work for Laravel 4 accordingly.
请参阅我对此问题的回答,我的示例适用于 L3,但应相应地适用于 Laravel 4。