PHP operates Last-Modified and etag to achieve further pseudo-static and 304

Source: Internet
Author: User

After a long history of pseudo-static exploration, we found that the following methods can be used to achieve pseudo-static SEO and reduce server pressure.
> Access the PHP page

> Last-Modified is generated based on the Content Update Time, And etag is generated based on the file name and content Update time.

> Compare the client data, such as viewing the Last-Modified of the client browser and comparing etag. If the values are the same, output 304 to stop outputting the latest data.

> If not, output the latest data as usual and return the Last-Modified and etag to the client.

/**
* Output head Last-Modified and determine whether to output 304.
*/
Protected function _ echo_last_etag ($ tmp_time ){
$ Now_url = get_absolute_url ();
$ Md5 = md5 ($ now_url. $ tmp_time );
$ Etag = '"'. $ md5 .'"';
Header ('Last-Modified: '. gmdate ('d, d m y h: I: s', $ tmp_time). 'gmt ');
Header ("ETag: $ etag ");
If (isset ($ _ SERVER ['HTTP _ IF_MODIFIED_SINCE ']) & amp; strtotime ($ _ SERVER ['HTTP _ IF_MODIFIED_SINCE']) & gt; = $ tmp_time) | (isset ($ _ SERVER ['HTTP _ IF_UNMODIFIED_SINCE ']) & amp; strtotime ($ _ SERVER ['HTTP _ IF_UNMODIFIED_SINCE']) & lt; $ tmp_time) | (isset ($ _ SERVER ['HTTP _ IF_NONE_MATCH ']) & amp; $ _ SERVER ['HTTP _ IF_NONE_MATCH '] = $ etag )){
Header ("HTTP/1.1 304 Not Modified ");
Exit (0 );
}

}


From Xiaoqiang's column

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.