开发者

How do I directly create and output a .gz file with PHP

开发者 https://www.devze.com 2023-04-12 22:18 出处:网络
I\'m making a dynamic sitemap and i want it gziped before ou开发者_JAVA百科tput. How do I do that? What header should I add?On this page two methods for sending gzipped output are outlined.

I'm making a dynamic sitemap and i want it gziped before ou开发者_JAVA百科tput. How do I do that? What header should I add?


On this page two methods for sending gzipped output are outlined.

The easiest solution is to use output buffering with the ob_gzhandler:

<?php
    ob_start("ob_gzhandler");
?>

The ob_gzhandler will take care of setting the correct headers. It also does not gzip the data in case the client does not support gzip encoding.

However, the ob_gzhandler requires that the Zlib library is enabled. For more details see the documentation of ob_gzhandler.

0

精彩评论

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