【问题标题】:Tailing a log within Laravel never executes Symfony Process callback在 Laravel 中拖尾日志永远不会执行 Symfony 进程回调
【发布时间】:2020-01-07 01:39:59
【问题描述】:

我正在尝试使用控制台命令跟踪日志文件以检测特定错误。但是,我的脚本的run(...) 部分中的回调从未在 Symfony 进程中调用:

use Illuminate\Console\Command;
use Symfony\Component\Process\Process;

class MonitorLogs extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'monitor:logs {log}';

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $command = "tail -n 1 -f " . escapeshellarg($this->argument('log'));

        (new Process($command))
            ->setTty(true)
            ->setTimeout(null)
            ->run(function ($type, $line) {
                $this->info('test');
            });
    }
}

我尝试使用 Xdebug 跟踪任何我在$this->info() 的断点从未到达。我可以在我正在测试的日志文件中添加行,当脚本运行时它们会显示在我的控制台中,但是输出单词 test 的行永远不会被命中。

这里有什么问题?

【问题讨论】:

    标签: php laravel symfony process laravel-6


    【解决方案1】:

    请删除setTty(true),输出应相应显示

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-09
      相关资源
      最近更新 更多