Jintor Posted August 25, 2021 Share Posted August 25, 2021 CONTEXT (1) : I know that output_buffer off + gzip output don't "mix" well together. CONTEXT (1) : But I need output_buffer off. TEST (1) : In php I can gzcompress(); $a = 'this is a sting'.'<br>'; $b = gzcompress($a,6); echo $b; // but the result is this x�+��,V�D��̼t��";D��� TEST (2) : if I add ( at the top of my php header('Content-Type:gzip;'); ==> the result is this xœ+ÉÈ,V�¢D…â’̼t›¤";�DáÉ (in the browser) QUESTION : So is there a way to digg deeper and "tell" the receiving browser to ungzip that output ?? Quote Link to comment https://forums.phpfreaks.com/topic/313602-food-for-thoughts-mixing-output_buffer-off-sending-gzipped-compressed-html/ Share on other sites More sharing options...
kicken Posted August 25, 2021 Share Posted August 25, 2021 6 minutes ago, Jintor said: CONTEXT (1) : But I need output_buffer off. Why? 7 minutes ago, Jintor said: QUESTION : So is there a way to digg deeper and "tell" the receiving browser to ungzip that output ?? Content-Encoding Quote Link to comment https://forums.phpfreaks.com/topic/313602-food-for-thoughts-mixing-output_buffer-off-sending-gzipped-compressed-html/#findComment-1589356 Share on other sites More sharing options...
requinix Posted August 25, 2021 Share Posted August 25, 2021 This should really be handled by the web server, not by PHP. Quote Link to comment https://forums.phpfreaks.com/topic/313602-food-for-thoughts-mixing-output_buffer-off-sending-gzipped-compressed-html/#findComment-1589357 Share on other sites More sharing options...
Jintor Posted August 25, 2021 Author Share Posted August 25, 2021 2 minutes ago, kicken said: Why? Content-Encoding what else can I try other than header('Content-Type:gzip;'); ?? **** FOR THE WHY : some php can take long time to execute, so outputting each echo gives "feed backs" to the user. 1 of many example : FFMPEG takes long time to convert, with PHP and can echo stuff while the ffmpeg is being executed to show the compression progress an other example : some advanced search => with a script that does many queries in different tables => echoing results while continue to search.... an other example : probing travel GDS API => echoing results as they come ** Handled by server in PHP ==> in apache or php.ini ? Quote Link to comment https://forums.phpfreaks.com/topic/313602-food-for-thoughts-mixing-output_buffer-off-sending-gzipped-compressed-html/#findComment-1589360 Share on other sites More sharing options...
Jintor Posted August 25, 2021 Author Share Posted August 25, 2021 Turns out I was deceived by https://tools.pingdom.com/ ..... it says I don't have gzip..... but other tools like https://www.webpagetest.org/show I do. I use Clouflare with brotli and http3 active... the brotli thing does compressed output each echo (output buffer on or off)... 😀 Quote Link to comment https://forums.phpfreaks.com/topic/313602-food-for-thoughts-mixing-output_buffer-off-sending-gzipped-compressed-html/#findComment-1589369 Share on other sites More sharing options...
kicken Posted August 25, 2021 Share Posted August 25, 2021 1 hour ago, Jintor said: **** FOR THE WHY : some php can take long time to execute, so outputting each echo gives "feed backs" to the user. That may or may not work as you expect. There are lots of potential buffers besides PHP's that can get in the way of trying to stream a response like that. If you want to provide incremental updates/progress notifications to a user you really need to design a system that will work with buffering enabled. Usually this takes the form of executing the task in the background on your server by some means and then outputting a page that uses Javascript to request periodic updates. Quote Link to comment https://forums.phpfreaks.com/topic/313602-food-for-thoughts-mixing-output_buffer-off-sending-gzipped-compressed-html/#findComment-1589370 Share on other sites More sharing options...
requinix Posted August 25, 2021 Share Posted August 25, 2021 WebSockets are also a possibility. They're more complicated to set up, but the advantage is that they're specifically designed to exchange messages like this: you start request to do something, socket emits periodic messages about progress, and it all closes down when complete. Quote Link to comment https://forums.phpfreaks.com/topic/313602-food-for-thoughts-mixing-output_buffer-off-sending-gzipped-compressed-html/#findComment-1589372 Share on other sites More sharing options...
Jintor Posted August 27, 2021 Author Share Posted August 27, 2021 On 8/25/2021 at 5:21 PM, requinix said: WebSockets are also a possibility. They're more complicated to set up, but the advantage is that they're specifically designed to exchange messages like this: you start request to do something, socket emits periodic messages about progress, and it all closes down when complete. I tried web sockets, but with the secure version wss => was "waiting the end of the script to push the info...." Quote Link to comment https://forums.phpfreaks.com/topic/313602-food-for-thoughts-mixing-output_buffer-off-sending-gzipped-compressed-html/#findComment-1589401 Share on other sites More sharing options...
Jintor Posted August 27, 2021 Author Share Posted August 27, 2021 On 8/25/2021 at 5:12 PM, kicken said: That may or may not work as you expect. There are lots of potential buffers besides PHP's that can get in the way of trying to stream a response like that. If you want to provide incremental updates/progress notifications to a user you really need to design a system that will work with buffering enabled. Usually this takes the form of executing the task in the background on your server by some means and then outputting a page that uses Javascript to request periodic updates. My apache is also at output buffer off I don't use NGINX and I uninstalled PHP-FPM from my server ==> note : since I did that my websites are 10x to 100x faster. ( I hope no one here will hire a hitman to finish me... when I said "remove PHP-FPM" in stackoverflow I was removed the right to ask new questions....... fans of PHP-FPM are angry at me. ) with all that => echo '1'; sleep(2); echo '2'; sleep(2); echo '3'; sleep(2); echo '4'; sleep(2); .... ==> I see 1, then wait, then 2, then wait, etc. => with PHP-FPM or "fast-cgi" or output_buffer on => i wait very long and then 123 This setup works with centos 7, centos8 and AlmaLinux Quote Link to comment https://forums.phpfreaks.com/topic/313602-food-for-thoughts-mixing-output_buffer-off-sending-gzipped-compressed-html/#findComment-1589402 Share on other sites More sharing options...
kicken Posted August 27, 2021 Share Posted August 27, 2021 45 minutes ago, Jintor said: This setup works with centos 7, centos8 and AlmaLinux If it works for you, and you're the only one that needs it working then by all means go ahead with the plan. If you need a general solution that works for any potential user then you're better off finding another way, as there may be other buffers you have no control over. For example, the user's browser or they may be using a proxy server that buffers. Quote Link to comment https://forums.phpfreaks.com/topic/313602-food-for-thoughts-mixing-output_buffer-off-sending-gzipped-compressed-html/#findComment-1589403 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.