Laravel 5 在浏览器中查看运行命令状态的进度条

Laravel 5 progress bar to see status of runing command in browser

我对Laravel 5有疑问:做实时页面是真的吗,我可以在其中运行 laravel 命令并在该页面上显示该命令的进度?

例如:我们有 60k 行的搜索索引,我们需要重建该索引,在 laravel 命令中我们可以使用 cycle 来完成,在每次迭代的 edn 中我们可以显示进度条命令行。

但是如何在浏览器页面显示呢? laravel 5 有一些软件包吗?或者其他解决方案?

也许有人知道一些解决方案如何从命令中检索答案并且不停止它,所以命令将 运行 异步?

谢谢。

我能想到的最简单的方法是将命令进度存储在像 memcache 或 redis 这样的缓存中,然后让前端查询该进度的缓存键。

Command/Backend:

$cache = new Memcache;
$cache->addServer('localhost', 'port');

foreach ($records as $key => $index) {
    $your_index->index($index);
    $cache->set('command_progress', ($key / count($records)) * 100);
}

前端:

$cache = new Memcache;
$cache->addServer('localhost', 'port');

$percentage = $cache->get('command_progress') ? : 0;
var_dump($percentage);

将前端代码放入 ajax 脚本中并不断轮询直到达到 100%。