Jump to content

Gzip file size


Cardale

Recommended Posts

I am sure it has to do with the output buffer not compressing till after the data is sent to the browser. Here is a test script I created which shows the difference, which seemed to work:

 

<?php
function output() {
echo "<div style=display:none>";
for ($i=0;$i<100;$i++) {
	echo str_repeat("One jumped over the coocoo nest!<br />", 100);
}
echo "</div>";
}

ob_start();
output();
$output = gzcompress(ob_get_contents());
ob_end_clean();

ob_start();
output();
$output2 = ob_get_contents();
ob_end_clean();

echo "Length is after compression: " . strlen($output) . "<Br />";
echo "Length is before compression: " . strlen($output2) . "<Br />";
?>

 

Seems to work, how are you setting up the compression? In .htaccess or using

ob_start('ob_gzhandler');

? If so that is why, because the output does not get compressed until the script ends essentially (or at least that is all I could come up with).

Link to comment
https://forums.phpfreaks.com/topic/184351-gzip-file-size/#findComment-975042
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.