Home >Backend Development >PHP Tutorial >HTTP protocol analysis series (9) ------http protocol and content compression

HTTP protocol analysis series (9) ------http protocol and content compression

WBOY
WBOYOriginal
2016-08-08 09:31:461408browse

Observe that we opened a news article from 163, and saw the following corresponding header information, and saw the following response header information. Note, Content-Length


At the same time, we Right-click to save the source code. The saved file size is


Thinking: Content-LengthIn the previous study, it represented the returned body length

But why are the body length and content-length returned here? What about inconsistencies?

The reason is that

Content-Encoding:gzipThis response header information is working

Principle: In order to improve the transmission speed of web pages on the network, the server compresses the main information. Such as the common

gzip compression, deflate compression, compress compression, and the sdch compression that google chrome is pushing.

The compression process is like this:


The reason for the situation just now is that the server compressed the page content-length

is the length after "compression"

How to enable it in

apache Compression function?

1. Enable the

deflate module, or the gzip module.

2.Write the following code in the conf file

3. Why do you need to specify the file type for compression?

Answer: Compression also consumes

CPU resources, and the compression effect is not good for pictures /movies/videos and other files.

It is generally a file in compressed text format.

<ifmodule mod_deflate.c>
DeflateCompressionLevel 6
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/atom_xml
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE image/svg+xml
</ifmodule>


Q: How does the server know that our browser supports gzip

?

Answer: The client is allowed to send an

accept-Encoding header message to negotiate with the server

This example can show the three types of chrome

browsers

Firefox only supports two compression methods

Tips: When we are collecting, we don’t need to send the Accept-Encoding

information, so that the source code is collected directly. Of course, we can also collect gzip (increase speed), and then use gzipDecompress the content.


The above introduces the HTTP protocol analysis series (9)------http protocol and content compression, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn