How to compress JSON with PHP?

前端 未结 3 1756
孤独总比滥情好
孤独总比滥情好 2020-12-13 14:46

I\'m writing a little analysis page which will help me hunt down bugs in an application. In essence it allows to visually compare actual data and log entries, plus perform a

相关标签:
3条回答
  • 2020-12-13 15:23

    In PHP 5.4 is now JSON_UNESCAPED_UNICODE so you can replace char:

    \u00f3 -> Ĺ› = Ś

    eq:

     json_encode($data,JSON_UNESCAPED_UNICODE);
    
    0 讨论(0)
  • 2020-12-13 15:28

    If apache is your choice (and it is, like mentioned in original question), you may add some rules into .htaccess:

    <IfModule mod_deflate.c>
        AddOutputFilterByType DEFLATE text/html
        # Add any mime-type you think is appropriate here
        AddOutputFilterByType DEFLATE application/json
    </IfModule>
    
    0 讨论(0)
  • 2020-12-13 15:32

    You can compress the data with PHP’s output control. Just put this call at the start of your script before any output:

    ob_start('ob_gzhandler');
    

    Now any output will be compressed with either gzip or deflate if accepted by the client.

    0 讨论(0)
提交回复
热议问题