【问题标题】:Laravel schedule works but command not workingLaravel 时间表有效,但命令不起作用
【发布时间】:2016-06-11 09:56:42
【问题描述】:

使用 laravel 时间表我有问题。计划运行但命令不起作用。这是示例。我每分钟都按计划发送邮件,并且还想每分钟运行命令以对其进行测试。命令不起作用。我没有收到来自命令的电子邮件(带有文本“命令已执行”)。我做错了什么? 请帮忙。

内核.php

class Kernel extends ConsoleKernel {

    protected $commands = [
        'App\Console\Commands\myCustomCommand'
    ];

    protected function schedule(Schedule $schedule) {

        //this works
        sendMailFunction('someone@gmail.com', 'test mail', 'schedule executed'); 

        //this is not working
        $schedule->command('command:myCustomCommand')->cron('* * * * *')
    }

}

命令

class myCustomCommand extends Command {


    protected $name = 'command:myCustomCommand';


    protected $description = 'some description';


    public function handle() {
        sendMailFunction('someone@gmail.com', 'test mail', 'command executed');
    }

}

【问题讨论】:

  • 也许你应该先从命令行测试你的命令?它返回什么错误?
  • 没有错误。从命令行它可以工作。我认为 cron() 函数不起作用。我也尝试了 everyMinute() 但仍然没有结果。我不知道为什么它不起作用
  • 你是否在你的服务器上运行了这个:* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1 来启用 Laravel 调度程序?
  • 是的调度程序工作。因为我每分钟都会收到来自日程安排的电子邮件,其中包含文本“已执行日程”
  • 嗯,真的很奇怪。 /storage/laravel.log中是否有任何与日程安排或发送邮件相关的错误?

标签: laravel command schedule


【解决方案1】:

在本地主机中:php artisan schedule:run

在主机中:* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1

你必须看看它是什么 要么 在 kernel.php 中引入你的控制器

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-17
    • 2020-05-29
    • 1970-01-01
    • 2015-05-26
    • 2013-09-25
    • 2015-09-24
    • 1970-01-01
    • 2014-04-01
    相关资源
    最近更新 更多