Jump to content

Output Buffering


Guest FirefoxRocks

Recommended Posts

Guest FirefoxRocks

Usually everyone recommends that you use gzip compression, which is done by the ob_start('ob_gzhandler'); function in PHP. However if you have multiple callback functions it doesn't work. How can I fix this?

<?php	header("Content-Type: text/css; charset=utf-8");	function callback($buffer) {// do some stuff		return $buffer;	}	ob_start("callback");	ob_start('ob_gzhandler');?>

Link to comment
Share on other sites

The best way is to move gzip to another layer. If you have .htaccess, use mod_deflate, assuming its on of course. Its name is misleading in Apache 2.2, as it uses gzip in that version (actually, it negotiates the encoding... but gzip is the preffered one). It only uses defalte in Apache 1.* AFAIK.If you have access to php.ini, you may instead use

zlib.output_compression = "On"

If you have none of these, you just have to make sure that 'ob_gzhandler' is executed last... I'd also avoid buffer flushing in that case, and do everything in the end.

Link to comment
Share on other sites

Guest FirefoxRocks

Ok I'll try the Apache method for now, but is there a way for .htaccess or something else to detect if a server is IIS or Apache?And about multiple output buffers, I still can't get it to work and it returns HTTP 500 errors.

Link to comment
Share on other sites

Ok I'll try the Apache method for now, but is there a way for .htaccess or something else to detect if a server is IIS or Apache?And about multiple output buffers, I still can't get it to work and it returns HTTP 500 errors.
Apache and IIS use two different configuration files, with different default names and different formats, so you can just create both of those files, and apply the same settings to them (in the corresponding format and all). Apache uses .htaccess and IIS uses web.config.
Link to comment
Share on other sites

Guest FirefoxRocks

Ok I tried the .htaccess method and it didn't work. Since I am using a web host and not my own server, I do not have access to Apache configuration files or the php.ini file. Is is safe to do this in .htaccess though?

php_value output_handler ob_gzhandler
Or will this cause issues with the server's processor?
Link to comment
Share on other sites

Assuming PHP is installed as an Apache module (which is unlikely - most shared hosts install it as CGI for security reasons), you may try that. You could also try:

php_flag zlib.output_compression on

(but not both this and the other one!)If it doesn't work, try to ask your host how/if you can do gzipping, and if they can assist you with your code... I mean, as far as I can see, your initial PHP script should've worked fine.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...