Laravel + Crontab 不工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42483935/
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
Laravel + Crontab not working
提问by prgrm
I am trying to set up scheduler in Laravel.
我正在尝试在 Laravel 中设置调度程序。
Here is my crontab which I debugged and works fine - atleast with my cron job
这是我调试并运行良好的 crontab - 至少在我的 cron 工作中
* * * * * /bin/echo "foobar" >> /my_path/example.txt
I don't know if this one works:
我不知道这个是否有效:
* * * * * php /var/www/myproject/artisan schedule:run 1>> /dev/null 2>&1
Here is my schedule function in Kernel:
这是我在内核中的调度功能:
protected function schedule(Schedule $schedule)
{
$schedule->command('inspire')
->everyMinute();
}
When I am in my project and try php artisan inspire
it actually works, so I expected it to fire every minute, but it won't do anything. Nothing happens.
当我在我的项目中并尝试php artisan inspire
它确实有效时,所以我希望它每分钟触发一次,但它不会做任何事情。没发生什么事。
Any ideas?
有任何想法吗?
回答by Rhu
This part just puts the output into oblivion so you'll never see it:
这部分只是将输出遗忘,所以你永远不会看到它:
>> /dev/null 2>&1
Why not try:
为什么不试试:
* * * * * php /var/www/myproject/artisan schedule:run >> /my_path/example.txt
And check to see if the cron is run in /my_path/example.txt
并检查 cron 是否在/my_path/example.txt 中运行
The default inspire command essentially just echo's a quote so the only way to see it in a cron is to output it to a file on the server.
默认的inspire 命令本质上只是echo 的引用,所以在cron 中查看它的唯一方法是将它输出到服务器上的文件。
You can do this using something similar to this:
您可以使用类似于以下内容的方法执行此操作:
$schedule->command('inspire')->everyMinute()->appendOutputTo($filePath);
Further details: https://laravel.com/docs/5.4/scheduling#task-output
回答by Muthu17
Am also using laravel 4.2, Here is my Cron command which currently working good.
我也在使用 laravel 4.2,这是我目前运行良好的 Cron 命令。
0 0 * * * /usr/local/bin/php /*****/******/public_html/artisan command:firemyevent
Hope It will help you.
希望它会帮助你。