Codeigniter not echoing only when script end to run

Viewed 42

I'm facing some problem with CI4 when I doing a loop and running on terminal (php index.php) I not seeing the echo on live, only when the script finish to run than its printing all of those echo together. In the past in CI3 I was seeing every loop printing on live to the terminal screen:

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

CI4 uses a special CLI library. To output text directly, use CLI::write. Extra linebreaks are not needed.

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);
        }
    }
}
Related