Http 1.1 Etag and last-modified improve PHP efficiency _php skills

Source: Internet
Author: User
Tags curl response code rfc

In today's Blog, some Web applications need to parse a lot of RSS feeds. How to improve efficiency is a very important issue. This is listed in Magpierss 's Features: HTTP Conditional GETs Save bandwidth and speed up download Intelligent use of last-modified and ETag. The Etag here caught my attention.

What is Etag?

By reading the RFC 2616 , I got a little impression of Etag:

The ETag response-header field provides the current value of the "entity" tag for the
requested variant ... Entity tags are normally "strong validators," but the protocol provides a mechanism to tag a Entity tag as "weak." One can of a strong validator as one that changes whenever the bits of a entity changes, while a weak value changes Whenever the meaning of an entity changes. Alternatively, one can of the a strong validator as part of the identifier for a specific entity, while a weak validator is part of the identifier for a set of semantically equivalent entities.

From the above we can roughly learn that Entity tags is essentially a "strong calibrator", but the HTTP protocol provides a "weak" mechanism for labeling Entity tags (similar to the content of the checksum code ). Although this passage is explained in two ways, it is still obscure. I read this passage only to come to the Etag "E" represents "Entity" just.

Magpie an article on the home page: HTTP Conditional get for RSS Hackers , read a lot clearer. First of all, the basic principle of HTTP Conditional GETs, very simple, that is, from the WEB server to take data, if the file changes, give me a new file, if the file does not change, just tell the client did not change, you do not have to retrieve the file. This can save a lot of network bandwidth and resources.

Etag and last-modified are concepts that are available from HTTP 1.0 through HTTP 1.1. When we get the files from the Web server, we just need to read the Etag and last-modified fields of the HTTP response header, and what's inside of these two fields is what you can do regardless of (may be strange,RFC 2616 has no specific value for Etag , the two values Cache in the local, the next check whether the file is updated when compared to these two values can be. If there is no change, the response code for the server is not HTTP (OK), but 304.

As pictured above. Openrss is currently subscribed to more than 40 feeds, but the response rate is very good. In the process of using Gregarius (Lilina also applied ETag), found feedburnrer burning Feed, almost all with ETAG (otherwise estimated server will be paralyzed, Hoho) . Let 's test the response of the HTTP header:

$ curl-i http://feeds.feedburner.com/dbanotes
http/1.1 OK
date:tue, Oct-11:34:15 GMT
Server : Apache
last-modified:tue, Oct 04:30:12 GMT
etag:u4q478bdklqz8ummc8a5afzuhug
content-type:text/xml;charset=utf-8

$ curl-i http://feeds.feedburner.com/dbanotes
  Etag:u4q478bdklqz8ummc8a5afzuhug 

During this period, my Blog has not been updated. So last-modified and ETag return the same values. So that Gregarius doesn't have to be parsed again. The domestic greatnews is to support the HTTP Conditional GETs , but also to support gzip/deflate encoding. Another RSS reader, popu (Zhou Botong), has no idea.

The above is my notes, if there is an understanding error, please correct me!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.