问题
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
回答1:
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();
}
}
来源:https://stackoverflow.com/questions/4839750/kohana-3-command-line-output-buffering