PHP static file returns 304,
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 the HTTP_IF_MODIFIED_SINCE
combined ETag in PHP to do this. 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:
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/920881.html www.bkjia.com true http://www.bkjia.com/PHPjc/920881.html techarticle php static file return 304, 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, such as ...