PHP controls the Web page Expiration Time program

Source: Internet
Author: User
Tags header
Sometimes we need to control the expiration time of pages such as the home page. But we use the ChinaCache CDN For example, so how to design to let him cache my content.

Sometimes we need to control the expiration time of pages such as the home page. But we use the ChinaCache CDN For example, so how to design to let him cache my content.

Of course, the prerequisite is to open a CDN in a function reload_into_ims on. So the user sent over the No-cache is not afraid. Because it will give No-cache to If-modified-since. So we write the program is mainly to if-modified-since control just fine. Remember, the caching system architecture is best controlled by the backend, so the best approach is to manage the expiration of the program. Oh, I only can php, just write one in PHP, the other program is the same.

See my following procedure, hehe, 5 minutes overdue.

<?php
$headers = Apache_request_headers ();
$client _time = (isset ($headers [' if-modified-since '])? Strtotime ($headers [' if-modified-since ']): 0);
$now =gmmktime ();
$now _list=gmmktime () -60*5;
if ($client _time< $now and $client _time > $now _list) {
Header (' last-modified: ' Gmdate (' d, D M Y h:i:s ', $client _time). ' GMT ', true, 304);
Exit (0);
}else{
Header (' last-modified: ' Gmdate (' d, D M Y h:i:s ', $now). ' GMT ', true, 200);
}
?>



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.