php - Using http's Last-Modified cache to read cached files?
天蓬老师
天蓬老师 2017-05-16 13:14:43
0
1
457

Recently studied the Last-Modified cache mechanism using http, which allows the browser to read the cache file.
$num = 4; //Simulate server data changes to determine whether the browser needs to read the cache file
if($num==4) {

  if( isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ){  
    $browserCachedCopyTimestamp = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);  
     if ( ( $browserCachedCopyTimestamp + 3600 ) > time() ) {  
        header("HTTP/1.1 304");  
        exit(1);  
     }  
  }  

}else{

    header('Last-Modified: '.gmdate('D, d M Y H:i:s',time())." GMT");  
    header('Expires: '.gmdate('D, d M Y H:i:s', time() + 3600)." GMT");  
    header("Cache-Control:max-age=3600");  
   
    for( $i=1; $i < 10 ; $i++ ){  
       echo "$i|";      
    }  

}
I tested above that the cache file can be read, but I just checked online and said it is

[Last-Modified and ETags request http headers are used together. The server first generates the Last-Modified/Etag tag. The server can later use it to determine whether the page has been modified and determine whether the file should continue to be cached]
Why use Last-Modified and ETags together? Don't understand.

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!