How can I return 304 for php static files? Prompt page not updated

Source: Internet
Author: User
How can I return 304 for php static files? Prompt page not updated

  1. Private function _ addEtag ($ file ){
  2. $ Last_modified_time = filemtime ($ file );
  3. $ Etag = md5_file ($ file );
  4. // Always send headers
  5. Header ("Last-Modified:". gmdate ("D, d m y h: I: s", $ last_modified_time). "GMT ");
  6. Header ("Etag: $ etag ");
  7. // Exit if not modified
  8. If (@ strtotime ($ _ SERVER ['http _ IF_MODIFIED_SINCE ']) = $ last_modified_time |
  9. @ Trim ($ _ SERVER ['http _ IF_NONE_MATCH ']) = $ etag ){
  10. Header ("HTTP/1.1 304 Not Modified ");
  11. Exit;
  12. }
  13. }

Note: This function can be called before static files (slices) are output.

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.