Jump to content

Food for thoughts : mixing output_buffer OFF + sending gzipped compressed html....


Jintor

Recommended Posts

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 ??

Link to comment
Share on other sites

2 minutes ago, kicken said:

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 ?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...."

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.