Cardale Posted December 8, 2009 Share Posted December 8, 2009 I am trying to figure out how to get the size of a file after it has been compressed using the output buffer I am using the ob get length and it only returns the original file size for some reason. Link to comment https://forums.phpfreaks.com/topic/184351-gzip-file-size/ Share on other sites More sharing options...
Cardale Posted December 10, 2009 Author Share Posted December 10, 2009 I know its a hard one. Link to comment https://forums.phpfreaks.com/topic/184351-gzip-file-size/#findComment-974560 Share on other sites More sharing options...
premiso Posted December 10, 2009 Share Posted December 10, 2009 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 More sharing options...
Cardale Posted December 11, 2009 Author Share Posted December 11, 2009 I actually live where that movie was filmed. Link to comment https://forums.phpfreaks.com/topic/184351-gzip-file-size/#findComment-975568 Share on other sites More sharing options...
Cardale Posted December 12, 2009 Author Share Posted December 12, 2009 Oh and btw I got it worked out a little different, but seems correct. Link to comment https://forums.phpfreaks.com/topic/184351-gzip-file-size/#findComment-975795 Share on other sites More sharing options...
Cardale Posted December 12, 2009 Author Share Posted December 12, 2009 Oh and with strlen that returns the bits bytes or what? Link to comment https://forums.phpfreaks.com/topic/184351-gzip-file-size/#findComment-975797 Share on other sites More sharing options...
Cardale Posted December 12, 2009 Author Share Posted December 12, 2009 never mind mb_strlen works good. For some reason I couldn't divide with strlen. Link to comment https://forums.phpfreaks.com/topic/184351-gzip-file-size/#findComment-975801 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.