CRON 作业 - LARAVEL - 输出
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39239638/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CRON JOB - LARAVEL - OUTPUT
提问by Léo Coco
Hi I'm running CRON JOB with Laravel
嗨,我正在用 Laravel 运行 CRON JOB
Function declaration in Laravel
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 - Setting
CRON 作业 - 设置
pathToArtisan schedule:run 2>&1 >> /home/log/cron_output.log
Log file output (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 &
The echo in the function schedule is displayed but the ones inside my command 1 and command 2 are not.
显示功能计划中的回显,但我的命令 1 和命令 2 中的回显不显示。
I tried
我试过
echo "test"; $this->info('test');
No files 1.log or 2.log where created neither /home/log/ or where the Kernel.php file is or Command folder
没有文件 1.log 或 2.log 没有创建 /home/log/ 或 Kernel.php 文件所在的位置或命令文件夹
Any ideas ?
有任何想法吗 ?
Thank you
谢谢
回答by avip
You should use the built-in task outputmethod in Laravel.
您应该使用Laravel 中内置的任务输出方法。
For example:
例如:
$file = 'command1_output.log';
$schedule->command('command1')
->sendOutputTo($file);
回答by Léo Coco
Everything is ok now.
现在一切正常。
$schedule->command('command1')
->sendOutputTo($file);
and inside your command
在你的命令中
$this->info('test')
The files are created in the root folder of my application so I didn't see them !
这些文件是在我的应用程序的根文件夹中创建的,所以我没有看到它们!
Thank you
谢谢