问题描述
我正在使用Kohana 3,并且我有一个扩展Kohana_Controller的控制器.我使用以下命令从命令行调用它:
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?
谢谢
推荐答案
它看起来像Kohana :: init()(可能在bootsrap中被调用)调用ob_start()
.这意味着该点之后的所有输出都包含在输出缓冲区中.要停止此操作,请在Controller的before方法中添加ob_end_flush()
以输出可能已经输出的所有内容,并关闭输出缓冲.之后发出的任何回声都应立即输出.
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.
因此您的代码如下:
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();
}
}
这篇关于Kohana 3命令行输出缓冲?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!