ETagsをPHPでコントロールすることはできるのだが、 ETagsは、もともとは、ウエブサーバーが生成するキャッシュコントロールとして 作られたものであり、PHPで使うものではないような気がする。 以下のラインはApacheの.htaccessで、 ETag を自動生成する方法である。 -------------------------------- FileETag INode MTime Size -------------------------------- ETagをiNodeから生成すると、ロードバランスで複数のサーバーを 使用している場合、同じファイルに違ったETagをつけてしまうことになる。 それ以外の方法では、ファイルの内容からハッシュを計算してそれを ETagに使う。これは計算に時間がかかる。 それに加えて、ETag はcookieのようにユーザートラッキングに 使えるという問題点もある。 結局、ETagの自動生成は効率が悪く、GoogleやYahooがやめたほうがいい という流れになった。(代わりに"Cache-Control"を薦めている) -------------------------------------------------------------------- https://www.askapache.com/htaccess/apache-speed-etags/ The problem with ETags is that they typically are constructed using attributes that make them unique to a specific server hosting a site. ETags won't match when a browser gets the original component from one server and later tries to validate that component on a different server, a situation that is all too common on Web sites that use a cluster of servers to handle requests. By default, both Apache and IIS embed data in the ETag that dramatically reduces the odds of the validity test succeeding on web sites with multiple servers. -------------------------------------------------------------------- そのために、巷のサーバーでは、ETagを自動的にremoveするような設定に なっている可能性がある。 .htaccessでは以下のラインでETagをremoveできる。 -------------------------------- Header unset ETag FileETag None -------------------------------- PHPで直接コントロールするなら、ETagは便利だと思うのだが、 多くのサーバーで、ETagを削除する設定がなされているのでは、 使用は控えたほうがいいだろう。