Re: compressed buffered output
| From: | Zeev Suraski | Date: | Tue, 21 Nov 2000 23:00:22 +0000 |
| Subject: | Re: compressed buffered output | ||
| References: | 1 2 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-38861@lists.php.net to get a copy of this message | ||
At 13:46 20/11/2000, André Langhorst wrote:
0:49 zeev-pts/4 mail:~/public_html> telnet 0 8080 Trying 0.0.0.0... Connected to 0 (0.0.0.0). Escape character is '^]'. GET /~zeev/test.php HTTP/1.0 Accept-Encoding: gzip HTTP/1.1 200 OK Date: Tue, 21 Nov 2000 22:49:38 GMT Server: Apache/1.3.12 (Unix) secured_by_Raven/1.4.3 mod_macro/1.1.1 PHP/4.0.4-dev X-Powered-By: PHP/4.0.4-dev Hello: world Content-Encoding: gzip Connection: close Content-Type: text/htmlThat should work... Works For Me (TM) :)1) well how did you check it (that it has been sent compressed)?
:jW-´_(+v«îâl9ÕÓ®q×Ò5:ÀƸû\¼g¡!Ãý³Üd0fÕèhdyÎèC¡ سúÐ|þðaÞò-{Ï!a%³M/àë0P¢ò°>ö¬óÄ@óÔçdD~¦ºmKÖyt$WY8àÄ Ryôoõv͸ëhhÈG.êÜ·5Ë+Ê·ý¢Ô
ÕæÍýpIo±²{ãÁ©îb&
µÚi®î¢Jö0>¶\T'Û²)Ì7ß§¯Fá@0ÁÉdÌCÆ£
Good enough? :)
This works with the current CVS.
test.php contains:
<?
header("Hello: world");
print "Testing 1234";
phpinfo();
?>
And the .htaccess for this directory contains:
php_value output_handler ob_gzhandler
ob_start("ob_gzhandler") results in a similar behavior.
2) due to my failures checking what a browser would get I decided to write the compressed stream to a file, doesn't fflush() work with OB functions? if not it should be fixed somehow, it's a very helpful function...Hmm, well, fflush() works on the real output mechanism, not the output buffering one. You'd have to flush the output buffer using one of the ob_end_*() functions first. If you want, you can then call fflush(), but I'm not sure whether it'd be helpful (depends on the context).
neither "ob_gzhandler" nor () fill my file with anything (both linux+w32) $a=50; ob_start("ob_gzhandler"); echo str_repeat('a',$a); $fp=fopen('test.txt','w+b'); fflush($fp); ob_end_flush();Hrm, what do you expect to happen here? How do you expect the output to go from the output buffer to $fp? To make long things short - nothing in this example gives PHP even a remote hint that the output should be written to $fp... PHP always uses the 'true' output device for output, and not any file handle. There's one exception - if output buffering is enabled. You can do what you meant to do doing this:
ob_start(); /* start output buffering */
ob_start("ob_gzhandler"); /* open a new buffer, with ob_gzhandler() as the handler */
...output...
ob_end_flush(); /* stop the inner output buffering. the output will go through ob_gzhandler(), and its output will go to the outer output buffer */
$fp = fopen(...);
fwrite($fp, ob_get_contents());
ob_end_clean(); /* get rid of what's in the buffer */
3) it does not work, ok. so I could not test - what is ob_get_contents() supposed to return a) compressed buffers b) uncompressed buffersob_get_contents() returns the output before it goes through any handlers. In this particular case, you can call gzencode() if you wish to see the encoded data. Zeev -- Zeev Suraski <zeev@zend.com> CTO, Zend Technologies Ltd. http://www.zend.com/