Kohana 3 Command line output buffering?

房东的猫 提交于 2020-01-14 09:52:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!