How do you make an etag that matches Apache?

后端 未结 4 1426
自闭症患者
自闭症患者 2021-02-04 10:13

I want to make an etag that matches what Apache produces. How does apache create it\'s etags?

4条回答
  •  天命终不由人
    2021-02-04 10:39

    Apache uses the standard format of inode-filesize-mtime. The only caveat to this is that the mtime must be epoch time and padded with zeros so it is 16 digits. Here is how to do it in PHP:

    $fs = stat($file);
    header("Etag: ".sprintf('"%x-%x-%s"', $fs['ino'], $fs['size'],base_convert(str_pad($fs['mtime'],16,"0"),10,16)));
    

提交回复
热议问题