开发者

in PHP - Is it possible to combine/concatenate several gzencode

开发者 https://www.devze.com 2023-02-14 10:05 出处:网络
I have a large page that downloads in gzip encoding. The portion of the file that changes betwee开发者_如何学运维n viewers is tiny.

I have a large page that downloads in gzip encoding. The portion of the file that changes betwee开发者_如何学运维n viewers is tiny. Idealy I'd like to gzencode() the large static piece and cache it, then combine it with a gzencoded version of the more dynamic stuff. Is this possible? If not, is there any other trick I could use to still serve this page gzencoded and in 1 request?


Actually, it works just fine. I just tested it. It's even documented (sort of) in the gzip man page.

Multiple compressed files can be concatenated. In this case, gunzip will extract all members at once. For example:

     gzip -c file1  > foo.gz
     gzip -c file2 >> foo.gz

Then

     gunzip -c foo

is equivalent to

     cat file1 file2

So in PHP you can call gzencode() multiple times. Like such:

   $string1 = "test1";
   $string2 = "test2";
   $output = gzencode($string1).gzencode($string2);

Sorry to necro the post, but this comes up on google for an unrelated search and wanted to correct the answer.


No. Neither the gzip format nor the deflate encoding allow for blocks to be concatenated together. And there is no built-in function in PHP to do so.

0

精彩评论

暂无评论...
验证码 换一张
取 消