Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kohana 3 Command line output buffering?

I am using Kohana 3 and I have a controller that extends Kohana_Controller. I call it from the command line using:

php /path/to//index.php --uri="url/path"

It works just fine, but this particular script takes a long time and during the execution I am echoing status messages (echo 'status message';) but none of the messages appear until after the script has completed executing.

I want to see the status messages as they are echoed, can anyone tell me how to do it?

Thanks

like image 723
Craig Nakamoto Avatar asked Jan 29 '11 22:01

Craig Nakamoto


1 Answers

It looks like Kohana::init() (likely called in your bootsrap) calls an ob_start(). This means that everything output after that point is contained in the output buffer. To stop this, in your before method in your Controller add ob_end_flush() to output anything that may have already been output and turn off output buffering. Any echo's you make after that should be output immediately.

So your code with look like:

  Controller_CLI extends Controller {
       public function before() {
              // empty the output buffre
              ob_end_flush();

              // call parent before() just incase there's anything 
              // in the parent before that you need/want to execute
              parent::before();
       }
  }
like image 154
Darryl Hein Avatar answered Oct 17 '22 04:10

Darryl Hein