问题是,仅在完成命令并且页面/UI之前显示输出才显示。 我尝试使用LiveWire的
Stream功能
use Symfony\Component\Console\Output\StreamOutput;
public function streamTest()
{
$stream = fopen('php://output', 'w');
$outputBuffer = new StreamOutput($stream);
Artisan::call('list', outputBuffer: $outputBuffer);
$this->stream(
to: 'output',
content: $this->output,
replace: true,
);
while ($content = stream_get_contents($outputBuffer->getStream())) {
$this->output .= $content;
}
}
上面的行为不起作用,我不知道为什么。我在使用流方面的经验非常有限,因此在该示例中可能存在一些明显的错误,但是我在网上找不到类似的东西。
fwiw,这是页面 我认为您无法从单个LiveWire调用中实时进行输出,因为Artisan::call
public function handle()
{
$process = new Process(['php', 'artisan', 'list']);
$process->setTimeout(0);
$process->start();
foreach ($process as $type => $data) {
// Append $data to a file or a database record
}
}
然后在LiveWire组件中,进行民意调查或订阅更新,读取新输出并将其附加到UI。这样,您就不会阻止主请求,并且会看到其生成的输出。