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