You don't mention what web server you are using, but I am going to go out on a limb here and guess Apache2. I hit almost the identical thing you describe. I was trying to get my cgi script to pass back information as it had it ready, instead of buffering the whole thing. Worked jiffy in curl, etc., but buffered in a browser (pretty much any browser), which was at least maddening. I went through the exact steps you describe. The resolution in my case was to modify sites-enabled/terrifico.com
configuration file in Apache2 (the line in question starts with
SetEnvIfNoCase
(You can ignore the stuff above and below that line, I'm just showing it for reference of where I placed it.)
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName test.terrifico.com
ServerAlias test.terrifico.com
SetEnvIfNoCase Request_URI \.cgi$ no-gzip dont-vary
DocumentRoot /var/www/test.terrifico.com
From staring at the network traffic going back and forth, it finally dawned on me that the browser was advertising that it accepted deflation for anything (that was text). That was the difference between the browser and curl, for example. The salient bit was
Accept-Encoding:gzip,deflate,sdch
There was a bit about chunking
, but that didn't impact this particular problem. So, the browser was requesting mod_deflate
to kick in, which defeated my carefully spewing out bytes as I got them in my cgi script. You could change it in the browser, but it seemed more sensible to change it on the server once for the works.
Perhaps this helps.
php_flag output_buffering Off
to get theOff
to work. – Boo