Codeigniter仅在脚本结束运行时才回显

xzabzqsa  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(143)

当我在终端(php index.php)上运行一个循环时,我遇到了CI4的一些问题,我没有看到实时的echo,只有当脚本完成运行时,它才将所有这些echo一起打印出来。过去在CI3中,我看到每个循环都实时打印到终端屏幕上:

$stop = 10000000000000000;
       
for($index_start=0;$index_start<$stop;$index_start+=10){
    echo $index_start."\n";
}
kd3sttzy

kd3sttzy1#

CI4使用特殊的CLI库。要直接输出文本,请使用CLI::write。不需要额外的换行符。

use CodeIgniter\Controller;
use CodeIgniter\CLI\CLI;

class Tools extends Controller
{
    public function test()
    {
        $stop = 10000000000000000;

        for ($index_start = 0; $index_start < $stop; $index_start +=10 )
        {
            CLI::write($index_start);
        }
    }
}

相关问题