ob_start + compress breaks served file outputs
<p>I am working in a MVC pattern situation here.</p>

<p>I have <code>index.php</code> as a base file, controllers located in <code>/controllers/</code> directory. If you go to <code>/stream/xIEjeEJWqs</code> for example <code>/controllers/streamcontroller.php</code> will be executed.</p>

<p><code>index.php</code> starts like this and it minifies an output that is about to be sent to browser:</p>

<pre><code>&lt;?php

function replace_tabs_newlines($content)
{
    require_once 'includes/min/lib/Minify/HTML.php';
    require_once 'includes/min/lib/Minify/CSS_MODIFIED.php';
    require_once 'includes/min/lib/JSMin.php';
    $content = Minify_HTML::minify($content, array(
        'cssMinifier' =&gt; array('Minify_CSS', 'minify'),
        'jsMinifier' =&gt; array('JSMin', 'minify')
    ));
    return $content;
}

ob_start('replace_tabs_newlines');
ob_implicit_flush(0);
...
</code></pre>

<p>So this code minfies whatever is being outputted, like this:</p>

<pre><code>&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;
            Minifies..
        &lt;/title&gt;
</code></pre>

<p>becomes <code>&lt;html&gt;&lt;head&gt;&lt;title&gt;Minifies..&lt;/title&gt;</code></p>

<p>So, problem is that streamcontroller.php has to output something as PNG, MP4, and other and when it <code>readfile()</code>-s a content, browser cannot recognize a content which is compressed by <code>index.php</code> in the beginning.</p>

<p>Extract from streamcontroller.php:</p>

<pre><code>case "png":
  header('Content-type:image/png');
  header('Content-Length: ' . filesize($file));     
  readfile($file);
  exit;
break;
</code></pre>

<p>Now my questions are following:</p>

<ol>
<li><p>What would you recommend, taking out <code>streamcontroller.php</code> from MVC? Having <code>streamer.php</code> next to <code>index.php</code> for example?</p></li>
<li><p>Adding check functionanility in <code>index.php</code>'s <code>replace_tabs_newlines($content)</code> function to check if browser is pointing at <code>streamcontroller.php</code> and do not do a minify job?</p></li>
<li><p>Maybe there is a way to stop <code>ob_start()</code>'s callback from being exacuted while being about to output something? ie: before <code>readfile()</code> in <code>streamcontroller.php</code>?</p></li>
<li><p>I will appreciate new ideas that are quite accepted in situations like this.</p></li>
</ol>
