Search code examples
phpcommand-line-interfaceechocodeigniter-4

echo to console in CLI script doesn't show in PHP CI4 (Code Igniter 4) until after the script terminates, how can I make it show in real-time?


Echoing to the console in a CLI script doesn't show in CI4 (Code Igniter 4) until after the script terminates/ends/exits.

I believe this is some security feature but in a CLI run, I'd like to be able to see those echo statements in real-time and not have to exit or stop my code to see what happened.

Is there a configuration for this somewhere or some way to change it easily? I've tried to research this but I must be searching for the wrong terminology, everything I find is irrelevant.

I am using PHP 8.0

Thanks for any help!


Solution

  • I found out that we can use CI4's built-in CLI write function and it will immediately output:

    use CodeIgniter\CLI\CLI;
    
    ...
    
    CLI::write('See this text immediately');