Any way to chunk gzip with Apache and PHP

I have a web application on a site that takes some time (~ 10 seconds) to complete part of the page at the bottom of the screen - it was as optimized as it could be, and caching is not an option.

We have compression allowed on the server using the .htaccess SetOutputFilter DEFLATE directive. The problem is that the whole page will be held until completion, before it starts to be displayed to the user, this is not optimal, since the user does not see anything until the page is completed.

I also tried it with the php method ob_start("ob_gzhandler"); .

I currently have <FilesMatch > in my .htaccess, which restricts the compression of this particular script.

Basically, my question is this: is there a way to tell chunk gzip or deflate so that the user gets it in pieces so that they can see the page start loading?

+4
source share
3 answers

I would say no. I think there is HTTP now.

+1
source

If you use the ob_start("ob_gzhandler") method, you can do this - you need to look at flush and ob_flush .

Some sample code - try downloading with curl or use a script to check for actual http responses

 <?php ob_start('ob_gzhandler'); print "chunk 1"; ob_flush(); flush(); sleep(2); print "chunk 2"; ob_end_flush(); 

Unfortunately, browsers do not seem to display this in chunks - I think this is because the data of each fragment is too small. You can test this effect by calling wget -O - -q http://chunktest/chunktest.php in the test file.

There are some more useful resources here.

+1
source

If the page is long loading time, the method of processing it is to use the page with very fast loading by ajax-call this content loaded on the page. We do this for pages that retrieve detailed usage statistics for members ... Other sites, such as Adsense, for example, do this on their reports page.

0
source

Source: https://habr.com/ru/post/1310279/


All Articles