Bug Report #1258
Kohana flushes its output buffer during `shutdown()` rather than `close_buffers()`
| Status: | Closed | Start date: | ||
|---|---|---|---|---|
| Priority: | High | Due date: | ||
| Assignee: | - | % Done: | 0% |
|
| Category: | Core | |||
| Target version: | 2.3.3 | |||
| Resolution: | fixed | Points: |
Description
Output buffering is A Good Thing, but disabling output_buffering in php.ini (or htaccess) allows streaming. Kohana's internal output buffering handles this configuration, but not when a Controller tries to stream. This affects downloads as evidenced in #1107.
I'm not sure how Kohana is expected to behave, but here is a test case and results with output compression disabled.
A_Controller::index() {
echo Kohana::debug('Before: '. ob_get_level());
Kohana::close_buffers();
echo Kohana::debug('After: '. ob_get_level());
echo "first content\n";
flush();
sleep(2);
echo "second content\n";
}
Kohana::close_buffers() {
echo Kohana::debug('close_buffers: '. ob_get_level() .':'. self::$buffer_level);
...
}
Current Results¶
PHP Output Buffering = 4096 (Large buffer)¶
Delay precedes all output. Not all content is shown.
(string) Before: 2 (string) close_buffers: 2:2
PHP Output Buffering = 2 (Small buffer)¶
Delay follows "first content". Kohana buffer is flushed late.
(string) After: 1 first content second content (string) close_buffers: 1:1 (string) Before: 2 (string) close_buffers: 2:2
PHP Output Buffering = 0 (Off)¶
Delay follows "first content". Kohana buffer is flushed late.
(string) After: 0 first content second content (string) close_buffers: 0:0 <!-- E_NOTICE Stack trace --> >system/core/Kohana.php r674: ob_end_clean() [ref.outcontrol]: failed to delete buffer. No buffer to delete. ... <!-- End Stack trace --> (string) close_buffers: 0:0 Notice: ob_end_clean() [ref.outcontrol]: failed to delete buffer. No buffer to delete. in /home/cbandy/projects/kohana/system/core/Kohana.php on line 674 (string) Before: 1 (string) close_buffers: 1:1
Related issues
History
Updated by Chris Bandy over 2 years ago
Upon further investigation, it is unreasonable for an application to flush the Kohana buffer since this buffer is passed to the system.display event during shutdown. To clear the buffer, one should call
Kohana::close_buffers(FALSE); Kohana::$output = '';
The ob_end_clean() error reported above occurs any time close_buffers() is called more than the number of buffer levels.
The attached patch fixes this error, clarifies comments surrounding output buffering, and makes output consistent for different PHP configurations.
Results after patch¶
PHP Output Buffering = 4096 (Large buffer)¶
Delay precedes all output. All content is shown.
(string) After: 1 first content second content (string) close_buffers: 1:2 (string) Before: 2 (string) close_buffers: 2:2
PHP Output Buffering = 2 (Small buffer)¶
Delay follows "first content". All content is shown.
(string) After: 1 first content second content (string) close_buffers: 1:2 (string) Before: 2 (string) close_buffers: 2:2
PHP Output Buffering = 0 (Off)¶
Delay follows "first content". All content is shown.
(string) After: 0 first content second content (string) close_buffers: 0:1 (string) Before: 1 (string) close_buffers: 1:1
Updated by Parnell Springmeyer over 2 years ago
- Status changed from New to Closed
- Resolution set to fixed