【发布时间】: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中是否有任何与日程安排或发送邮件相关的错误?