The JSON-formatted data returned in the PHP program is compressed with gzip output method, Jsongzip
1. Comparison of HTTP output with compression and not using compression
2. Turn on gzip
Use Apache Mod_deflate module to open gzip
To open a method:
sudo a2enmod deflatesudo/etc/init.d/apache2 restart
Close method:
sudo a2dismod deflatesudo/etc/init.d/apache2 restart
3. Set the type of output that requires gzip compression
The output type of JSON is Application/json, so you can set this
Join in the httpd.conf
Addoutputfilterbytype DEFLATE Application/json
<?php$data = Array (' name ' = ' = ' one ', ' value ' =>1), Array (' name ' = ' = ') ', ' value ' =>2), Array (' name ' = ' three ', ' value ' =>3), Array (' name ' = ' four ', ' value ' =>4), Array (' name ' = > ' Five ', ' value ' =>5), Array (' name ' = = ' six ', ' value ' =>6), Array (' name ' = ' = ' seven ', ' value ' = >7), Array (' name ' = ' eight ', ' value ' =>8), Array (' name ' = ' = ' nine ', ' value ' =>9), Array (' Name ' = ' ten ', ' Value ' =>10), header (' Content-type:application/json '); Echo Json_encode ($data);? >
To set the pre-gzip output:
After setting the GZIP output:
4. Single JSON compressed output using gzip
After you set Addoutputfilterbytype DEFLATE Application/json, all data output in JSON format will use gzip compression output.
If you only want to use gzip compression output for one JSON, you can use the Ob_start () method to implement the other.
First, you do not need to set Addoutputfilterbytype, and then add Ob_start (' Ob_gzhandler ') at the beginning of the code;
<?phpob_start (' Ob_gzhandler '); $data = Array (' name ' = ' = ' one ', ' value ' =>1), Array (' name ' = = ' Both ', ' value ' =>2), Array (' name ' = ' = ' three ', ' value ' =>3), Array (' name ' = ' four ', ' value ' =>4), Array ( ' name ' = ' = ' five ', ' value ' =>5), Array (' name ' = ' = ' six ', ' value ' =>6), Array (' name ' = = ') Seven ', ' value ' =>7), Array (' name ' = ' = ' eight ', ' value ' =>8), Array (' name ' = ' = ' nine ', ' Value ' =>9) , Array (' name ' = ' ten ', ' Value ' =>10), header (' Content-type:application/json '); Echo Json_encode ($data);? >
Articles you may be interested in:
- jquery sends requests to the PHP server via AJAX and returns JSON data
- PHP Simple implementation Query database return JSON data
- PHP implementation returns JSON and XML class sharing
- Thinkphp two implementations of JSON return via Ajax
- The PHP json_encode () function returns the JSON data instance code
- PHP returns JSON data function instance
- Workaround for PHP to handle JSON string decoding return null
- Ajax handles PHP instance code that returns JSON data
http://www.bkjia.com/PHPjc/1106125.html www.bkjia.com true http://www.bkjia.com/PHPjc/1106125.html techarticle The JSON-formatted data returned in the PHP program is compressed with gzip output method, Jsongzip 1. Use compression compared to HTTP output that does not use compression 2. Turn on gzip using Apache Mod_deflate module to open ...