CRON JOB - LARAVEL - OUTPUT

Léo*_*oco 12 cron laravel

嗨,我正和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);

}
Run Code Online (Sandbox Code Playgroud)

CRON JOB - 设定

pathToArtisan schedule:run 2>&1 >> /home/log/cron_output.log
Run Code Online (Sandbox Code Playgroud)

日志文件输出(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 &
Run Code Online (Sandbox Code Playgroud)

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

我试过了

echo "test"; $this->info('test');
Run Code Online (Sandbox Code Playgroud)

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

有任何想法吗 ?

谢谢

avi*_*vip 22

您应该使用Laravel中的内置任务输出方法.

例如:

$file = 'command1_output.log';
$schedule->command('command1')
         ->sendOutputTo($file);
Run Code Online (Sandbox Code Playgroud)

  • 谢谢.在我的情况下,我更喜欢`appendOutputTo`. (3认同)

Léo*_*oco 6

现在一切正常。

$schedule->command('command1')
     ->sendOutputTo($file);
Run Code Online (Sandbox Code Playgroud)

在你的命令中

$this->info('test')
Run Code Online (Sandbox Code Playgroud)

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

谢谢