php5 config?

Hi all,

Here is a tricky one:

(disclaimer: I know nothing of PHP)

I am using a blank Joomla template to create a new template for a www/joomla25 site. This template uses a file called css/template.css.php to load the template's CSS files and send them as one long compacted string (minimized) (code below).

On my FreeBSD server (PHP 5.3.13) template.css.php returns garbage:

http://wfbrace.com:8000/templates/wfbrace/css/template.css.php?b=0&v=1

Wit the same template installed for test purposes on a production server running some Linux (PHP 5.3.10), hosted at Byte.nl, template.css.php returns the CSS, in MIN form:

https://www.sense-online.nl/templates/wfbrace.com/css/template.css.php?b=0&v=1

What could be going wrong on my FreeBSD server? A wrong PHP setting? A missing php5 module?

Thanks.

PHP:
<?php 
/*------------------------------------------------------------------------
# author    your name or company
# copyright Copyright © 2011 example.com. All rights reserved.
# @license  [url=http://www.gnu.org/licenses/gpl-2.0.html]http://www.gnu.org/licenses/gpl-2.0.html[/url] GNU/GPL
# Website   [url=http://www.example.com]http://www.example.com[/url]
-------------------------------------------------------------------------*/

// parameter
$bootstrap = $_GET['b'];

//initialize ob_gzhandler to send and compress data
ob_start ("ob_gzhandler");
//initialize compress function for whitespace removal
ob_start("compress");
//required header info and character set
header("Content-type:text/css; charset=UTF-8");
//header("Content-type:text/css; charset=US-ASCII");
//cache control to process
header("Cache-Control:must-revalidate");
//duration of cached content (1 hour)
$offset = 60 * 60 ;
//expiration header format
$ExpStr = "Expires: " . gmdate("D, d M Y H:i:s",time() + $offset) . " GMT";
//send cache expiration header to broswer
header($ExpStr);
//Begin function compress
function compress($buffer) {
	//remove comments
	$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
	//remove tabs, spaces, new lines, etc.        
	$buffer = str_replace(array("\r\n","\r","\n","\t",'  ','    ','    '),'',$buffer);
	//remove unnecessary spaces        
	$buffer = str_replace('{ ', '{', $buffer);
	$buffer = str_replace(' }', '}', $buffer);
	$buffer = str_replace('; ', ';', $buffer);
	$buffer = str_replace(', ', ',', $buffer);
	$buffer = str_replace(' {', '{', $buffer);
	$buffer = str_replace('} ', '}', $buffer);
	$buffer = str_replace(': ', ':', $buffer);
	$buffer = str_replace(' ,', ',', $buffer);
	$buffer = str_replace(' ;', ';', $buffer);
	$buffer = str_replace(';}', '}', $buffer);
	
	return $buffer;
}

if ($bootstrap==1) require('bootstrap.css');
if ($bootstrap==0) require('reset.css');
                   require('template.css');
if ($bootstrap==1) require('bootstrap-responsive.css');

require('../../../media/system/css/system.css');
require('../../system/css/system.css');
require('../../system/css/general.css');
?>
 
If I request the file by hand with a simple HTTP request I get it fine, but in a web browser it's messed up.

I'm wondering if you're gzipping the data twice. My handmade request had no 'Accept-Encoding' header, so the server should not have tried to gzip the content, but it would with the web browser.

Can you try removing the following line:

Code:
ob_start ("ob_gzhandler");

I have never used this, I usually just configure an output filter via the web server to compress all relevant mime types. It's possible you are passing the content through ob_gzhandler in PHP to compress the data, and then the web server is configured to compress any text/css data, so is doing it again.
 
Back
Top