CRON JOB - LARAVEL - OUTPUT

时间:2016-08-31 02:04:51

标签: laravel cron

您好我用Laravel

运行CRON JOB

Laravel中的函数声明

protected function schedule(Schedule $schedule)
{
    echo "test CRON JOB\n";
    $file1 = '1.log';
    $file2 = '2.log';
    $schedule->command('command1')->sendOutputTo($file1);
    $schedule->command('command2')->sendOutputTo($file2);

}

CRON JOB - 设置

pathToArtisan schedule:run 2>&1 >> /home/log/cron_output.log

日志文件输出(cron_output.log)

test CRON JOB
Running scheduled command: '/opt/alt/php55/usr/bin/php' 'artisan'command1 > '1.log' 2>&1 &
Running scheduled command: '/opt/alt/php55/usr/bin/php' 'artisan' command2 > '2.log' 2>&1 &

显示功能计划中的回显,但命令1和命令2中的回显不是。

我试过

echo "test"; $this->info('test');

没有文件1.log或2.log既不创建/ home / log /,也不创建Kernel.php文件或Command文件夹

有什么想法吗?

谢谢

3 个答案:

答案 0 :(得分:19)

您应该在Laravel中使用内置的task output方法。

例如:

$file = 'command1_output.log';
$schedule->command('command1')
         ->sendOutputTo($file);

答案 1 :(得分:1)

现在一切都好。

$schedule->command('command1')
     ->sendOutputTo($file);

并在你的命令中

$this->info('test')

文件是在我的应用程序的根文件夹中创建的,所以我没有看到它们!

谢谢

答案 2 :(得分:1)

$schedule->command('my:command')
     ->daily()
     ->onSuccess(function () {
         // The task succeeded...
//set flag here and store to DB
     })
     ->onFailure(function () {
         // The task failed...
//set flag here and store to DB
     });

在管理仪表板中显示列表,以便您可以使用这些标志(cron 状态)检查日志

相关问题