Bug Report #1107

download helper causes an error

Added by liuxin - almost 3 years ago. Updated over 2 years ago.

Status:Closed Start date:
Priority:High Due date:
Assignee:Chris Bandy % Done:

0%

Category:Helpers
Target version:2.4
Resolution:fixed Points:

Description

I get an error when I running the download helper(listed below). I think it's because of the 'Kohana::close_buffers(FALSE);' function. When I change Kohana::close_buffers(FALSE); to 'ob_clean();', everything works fine

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Runtime Message</title>
<base href="http://php.net/" />
</head>
<body>
<style type="text/css">
div#framework_error { background:#fff; border:solid 1px #ccc; font-family:sans-serif; color:#111; font-size:14px; line-height:130%; }
div#framework_error h3 { color:#fff; font-size:16px; padding:8px 6px; margin:0 0 8px; background:#f15a00; text-align:center; }
div#framework_error a { color:#228; text-decoration:none; }
div#framework_error a:hover { text-decoration:underline; }
div#framework_error strong { color:#900; }
div#framework_error p { margin:0; padding:4px 6px 10px; }
div#framework_error tt,
div#framework_error pre,
div#framework_error code { font-family:monospace; padding:2px 4px; font-size:12px; color:#333;
    white-space:pre-wrap; /* CSS 2.1 */
    white-space:-moz-pre-wrap; /* For Mozilla */
    word-wrap:break-word; /* For IE5.5+ */
}
div#framework_error tt { font-style:italic; }
div#framework_error tt:before { content:">"; color:#aaa; }
div#framework_error code tt:before { content:""; }
div#framework_error pre,
div#framework_error code { background:#eaeee5; border:solid 0 #D6D8D1; border-width:0 1px 1px 0; }
div#framework_error .block { display:block; text-align:left; }
div#framework_error .stats { padding:4px; background: #eee; border-top:solid 1px #ccc; text-align:center; font-size:10px; color:#888; }
div#framework_error .backtrace { margin:0; padding:0 6px; list-style:none; line-height:12px; }</style>
<div id="framework_error" style="width:42em;margin:20px auto;">
<h3>Runtime Message</h3>
<p>An error was detected which prevented the loading of this page. If this problem persists, please contact the website administrator.</p>
<p><tt>F:/xampp/htdocs/web/system/core/Kohana.php <strong>r694:</strong></tt></p>
<p>1 ob_end_clean() [<a href='ref.outcontrol'>ref.outcontrol</a>]: failed to delete buffer. No buffer to delete.</p>
<h3>Stack Trace</h3>
<ul class="backtrace"><li><tt>F:\xampp\htdocs\web\system\core\Kohana.php <strong>r694:</strong></tt>
ob_end_clean(  )
</li>
<li><tt>F:\xampp\htdocs\web\system\core\Kohana.php <strong>r709:</strong></tt>
Kohana::close_buffers( 1 )
</li>
<li>
Kohana::shutdown(  )
</li>
<li><tt>F:\xampp\htdocs\web\system\core\Event.php <strong>r209:</strong></tt>
call_user_func( Array
(
    r0 =&gt; Kohana
    r1 =&gt; shutdown
)
 )
</li>
<li><tt>F:\xampp\htdocs\web\system\core\Bootstrap.php <strong>r58:</strong></tt>
Event::run( system.shutdown )
</li>
<li><tt>index.php <strong>r122:</strong></tt>
require( F:\xampp\htdocs\web\system\core\Bootstrap.php )
</li></ul><p class="stats">Loaded in {execution_time} seconds, using {memory_usage} of memory. Generated by Kohana v{kohana_version}.</p>
</div>
</body>
</html><br />
<b>Notice</b>: ob_end_clean() [<a href='ref.outcontrol'>ref.outcontrol</a>]: failed to delete buffer. No buffer to delete. in <b>F:\xampp\htdocs\web\system\core\Kohana.php</b> on line <b>694</b><br />

Related issues

blocked by Kohana v2.x - Bug Report #1258: Kohana flushes its output buffer during `shutdown()` rath... 2.3.3 Closed

History

Updated by Woody Gilk almost 3 years ago

The useful part of that error trace is:

ob_end_clean() [ ref.outcontrol ]: failed to delete buffer. No buffer to delete.

Updated by Akeru - almost 3 years ago

I also hit this issue...as a quick (and dirty fix) I simply set the error_reporting to 0 int he Kohana.php file at line 694.

Updated by Chris Bandy almost 3 years ago

I can confirm this happens at shutdown when one calls Kohana::close_buffers() in a controller. Debugging, I found ob_get_level() === Kohana::$buffer_level === 0 during Kohana::shutdown().

Changing the condition in close_buffers as below seemed to fix.

-  if (ob_get_level() >= self::$buffer_level)
+  if (ob_get_level() AND ob_get_level() >= self::$buffer_level)

Updated by Chris Bandy almost 3 years ago

Behavior depends on output_buffering in php.ini. More testing needed.

Updated by Caco Patane over 2 years ago

I've tried Chris patch 'system/core/Kohana.php' and worked fine. I use Kohana 2.3.2, and example of use of download::force() in a controller is:

public function get_import_template() {
        $out = implode(Kohana::config('contacts.import_sep'), array_keys($this->contact->get_contact_skel()));
        return download::force($filename='template.csv', $data=$out);
}

Prior to the patch, the downloaded file was appended with the error.

Updated by Jeremy Bush over 2 years ago

Was this fixed with #1258?

Updated by Jeremy Bush over 2 years ago

  • Target version changed from 2.3.3 to 2.4

Updated by Jeremy Bush over 2 years ago

  • Status changed from New to Assigned
  • Assignee set to Chris Bandy
  • Priority changed from Normal to High
  • 11 set to 2.3.4

Updated by Chris Bandy over 2 years ago

  • Status changed from Assigned to Closed
  • Resolution set to fixed

Also available in: Atom PDF