PHP static file return
sometimes some static files (slices) will be output by PHP, will find that the request is 200, static files each time to go to the server to request too much waste of resources, then how to let the browser cache pictures? We need to output 304 in PHP.
We can use http_if_modified_since in PHP to do this with the etag. The etag does not have a clearly defined format, we can use the MD5 value of the file modification time, the code is as follows:
The code is as follows:
Private Function _addetag ($file) {
$last _modified_time = Filemtime ($file);
$etag = Md5_file ($file);
Always Send headers
Header ("last-modified:". Gmdate ("D, D M Y h:i:s", $last _modified_time). " GMT ");
Header ("Etag: $etag");
Exit If not modified
if (@strtotime ($_server[' http_if_modified_since ') = = = $last _modified_time | |
@trim ($_server[' http_if_none_match ') = = = $etag) {
Header ("http/1.1 304 not Modified");
Exit
}
}
You can call it before the static file (slice) output in your code.
http://www.bkjia.com/PHPjc/991645.html www.bkjia.com true http://www.bkjia.com/PHPjc/991645.html techarticle php static file return sometimes some static files (slices) will be output by PHP, will find that the request is 200, static files each time to go to the server to request too wasted resources, then how to let the bangs ...