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.
The above describes the PHP static file return 304, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.