PHP setting static Content Cache time method, PHP set static cache _php Tutorial

Source: Internet
Author: User

PHP set static Content cache time method, PHP set static cache


This example describes how PHP sets the time for static content caching. Share to everyone for your reference. The specific methods are analyzed as follows:

In the use of Baidu tools to make a small test prompt we need to set the static content cache time, I do not have server permissions operation, can only start from other aspects, my own study of PHP after I found that you can use the header function to implement the browser cache page time, specifically as follows.

Set the static content cache time with the following code:
Copy the Code code as follows: $interval = 60 * 60 * 6; 6 hours
Header ("last-modified:".) Gmdate (' R ', $max));
Header ("Expires:".) Gmdate ("R", ($max + $interval)));
Header ("cache-control:max-age= $interval");
We add the above code to the beginning of the PHP file, below to give you a detailed explanation of the four lines of code, the code is as follows:
Copy the Code code as follows: $interval = 60 * 60 * 6; 6 hours
Header ("last-modified:".) Gmdate (' R ', $max));
Header ("Expires:".) Gmdate ("R", ($max + $interval)));
Header ("cache-control:max-age= $interval");
$aid = Intval (isset ($_post[' aid '))? $_post[' aid ']:0);
if (! $aid)
{
echo ' undefined advertisement ';
}
else if ($aid ==1)
{
echo ' load ad content ';
}
The first line: $interval tell you to set up 6 hours, here everyone can customize.

The second line: sends a last-modified request to the client browser, which invokes the corresponding date according to the gmdate parameter R.

The third line: Set the Expires expiration time.

Line four: Set Cache-control's max-age= $interval date.

The results of the re-test were excellent.

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/920622.html www.bkjia.com true http://www.bkjia.com/PHPjc/920622.html techarticle PHP set static content cache time method, PHP set static cache This article describes how PHP sets the static content cache time. Share to everyone for your reference. Concrete Method Analysis ...

  • 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.