Laravel + Crontab无法正常工作 [英] Laravel + Crontab not working

查看:72
本文介绍了Laravel + Crontab无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Laravel中设置调度程序.

I am trying to set up scheduler in Laravel.

这是我调试的crontab,并且工作正常-与我的cron工作至少一样

Here is my crontab which I debugged and works fine - atleast with my cron job

* * * * * /bin/echo "foobar" >> /my_path/example.txt 

我不知道这是否可行:

* * * * * 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();
    }

当我在项目中并尝试 php artisan inspire 时,它实际上可以工作,因此我希望它每分钟都能触发一次,但它不会做任何事情.什么都没发生.

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.

有什么想法吗?

推荐答案

这部分只是把输出遗忘了,所以您将永远看不到它:

This part just puts the output into oblivion so you'll never see it:

>> /dev/null 2>&1

为什么不尝试:

* * * * * php /var/www/myproject/artisan schedule:run >> /my_path/example.txt 

然后检查cron是否在/my_path/example.txt

And check to see if the cron is run in /my_path/example.txt

默认的inspire命令实际上只是回声一个引号,因此在cron中查看它的唯一方法是将其输出到服务器上的文件中.

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.

您可以使用与此类似的方法进行操作:

You can do this using something similar to this:

$schedule->command('inspire')->everyMinute()->appendOutputTo($filePath);

更多详细信息: https://laravel.com/docs/5.4/scheduling#task-输出

这篇关于Laravel + Crontab无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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