I am working in a MVC pattern situation here.
I have index.php as a base file, controllers located in /controllers/ directory. If you go to /stream/xIEjeEJWqs for example /controllers/streamcontroller.php will be executed.
index.php starts like this and it minifies an output that is about to be sent to browser:
<?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' => array('Minify_CSS', 'minify'),
'jsMinifier' => array('JSMin', 'minify')
));
return $content;
}
ob_start('replace_tabs_newlines');
ob_implicit_flush(0);
...
So this code minfies whatever is being outputted, like this:
<html>
<head>
<title>
Minifies..
</title>
becomes <html><head><title>Minifies..</title>
So, problem is that streamcontroller.php has to output something as PNG, MP4, and other and when it readfile()-s a content, browser cannot recognize a content which is compressed by index.php in the beginning.
Extract from streamcontroller.php:
case "png":
header('Content-type:image/png');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
break;
Now my questions are following:
-
What would you recommend, taking out
streamcontroller.phpfrom MVC? Havingstreamer.phpnext toindex.phpfor example? -
Adding check functionanility in
index.php‘sreplace_tabs_newlines($content)function to check if browser is pointing atstreamcontroller.phpand do not do a minify job? -
Maybe there is a way to stop
ob_start()‘s callback from being exacuted while being about to output something? ie: beforereadfile()instreamcontroller.php? -
I will appreciate new ideas that are quite accepted in situations like this.
How about adding an
ob_end_cleanbefore thereadfile