Laravel中的命令时间表 [英] Command schedule in Laravel

查看:99
本文介绍了Laravel中的命令时间表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试每隔五分钟在后台执行一次调度的命令.我使用这段代码

protected function schedule(Schedule $schedule)
    {

        $schedule->command('read:mail')->cron('*/1 * * * * *')->sendOutputTo(storage_path().'/logs/output.txt')->withoutOverlapping();

    } 

当我使用php artisan scheduler:run命令时,我认为这段代码很好,但是在后台每隔五分钟不起作用. ??有什么主意吗?

解决方案

如果要使用调度程序,则需要在服务器中添加Cron条目,此行将每分钟调用Laravel调度程序并执行任务. /p>

您需要在Crontab中添加以下行:

* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1

如果您正在使用 Ubuntu 来编辑crontab,则可以运行crontab -e并在底部添加该行.

您可以阅读有关计划的官方文档的更多信息.

如果您使用的是 Windows ,则可以遵循 解决方案

If you want to use the scheduler you need to add a Cron entry in your server, this line will call the Laravel scheduler every minute and do the tasks.

There is the line you need to add to your Crontab:

* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1

In case you are using Ubuntu to edit your crontab you can run crontab -e and add the line on the bottom.

You can read more on the official docs about Scheduling.

If you are using Windows you can follow this Stackoverflow question to add a task to the Windows task scheduler.

这篇关于Laravel中的命令时间表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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