开发者

Header Cache Expire - dynamic site and ad server clicks?

开发者 https://www.devze.com 2023-04-08 15:52 出处:网络
I did some research on speeding up your php mysql site. We update new information on our site every 12 to 24 hours.

I did some research on speeding up your php mysql site. We update new information on our site every 12 to 24 hours.

I found that Header Expire Cache Control in the browser h开发者_JAVA技巧elps speed up the site.

Here is my code:

Header("Cache-Control: must-revalidate");

 $offset = 60 * 60 * 24 * 3;
 $ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
 Header($ExpStr);

I am wondering, how do I change this to 1 hour instead of 3 days, also --

How are my ads on our site getting effected with browser cache enabled? Does it still count impressions and clicks?


Just for the record, you can also use a string representation instead of adding seconds up:

Header("Cache-Control: must-revalidate");

$offset = strtotime('+42 hours'); // same as time() + 42 * 60 * 60
$ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", $offset) . " GMT";
Header($ExpStr);


Change $offset to:

$offset = 60 * 60; (60 seconds / minute * 60 minutes / hour) = 3600 seconds / hour = 1 hour

Generally ads are served off different servers and the requests for the ad content will have their own expiry headers. So whatever you change the cache settings to on your server's content won't affect the content loaded from the external ad servers.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号