php - Laravel - 将控制台输出写入日志文件

标签 php laravel

我有一个输出一些行的命令:

/**
  * Execute the console command.
  *
  * @return mixed
  */
public function handle()
{
    $this->line('');
    $this->info('--------------------------------------------------------');
    $this->info('----------------- Compress documents -------------------');
    $this->info('--------------------------------------------------------');
    $this->line('');
    $progressBar = $this->output->createProgressBar(3);
    $this->info('Selecting files...');
    // ...
    $progressBar->advance();
    $this->info('Processing...');
    // ...
    $progressBar->advance();
    $this->info('Moving files...');
    // ...
    $progressBar->advance();
    $this->info('--------------------------------------------------------');
    $this->info('------------------------ Result ------------------------');
    $this->info('--------------------------------------------------------');
    // ...
    $this->info('Output quality: '.$resolution.'%');
    $this->info('Processed files: '.sizeof($files));
    $this->info('Original size: '.number_format($originalPathSize, 3).'MB');
    $this->info('Compressed size:'.number_format($compressedPathSize, 3).'MB');
    $this->info('Improvement: '.number_format($compressedPathSizeDiff, 3).'MB ('.number_format($compressedPathSizeDiffPercent, 3).'%)');
    $this->info('Total time: '.$timeFormatted);
    // ...
    $this->table($headers, $rows);
    $this->info('Ready!');
}

它就像一个魅力。

问题是,现在我需要在生产服务器中运行此命令(通过 SSH),并且必须花费几个小时才能处理所有文件。显然我不想在此期间保持登录状态来查看控制台输出。

与调度任务一样,有某种方法可以将控制台命令输出“自动”写入日志文件吗?

最佳答案

您可以使用screen Linux命令。 Screen Example

您可以保存输出,例如

#screen
#php artisan command > /etc/commandResults.log

关于php - Laravel - 将控制台输出写入日志文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56807493/

相关文章:

php - 为什么QueryBuilder忽略我的输入参数?

php - Laravel Auth - 使用 md5 而不是集成的 Hash::make()

Laravel 更新不起作用告诉 _method 未知列

php - 插入新更新时将以前的状态更新为“死亡”

pHp 函数 - 测试我的变量是否存在以及是否满足条件

javascript - AJAX 错误状态代码 500 内部服务器错误

mysql - 获取具有关系的嵌套 json 数据 Laravel Eloquent 模型

javascript - 在 laravel blade 模板里面写一个 js 表达式

SQL查询的PHP大量内存使用

php - 我该如何解决这个 : The column 'created_at' conflicts with another column in the mapper