Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you make an etag that matches Apache?

Tags:

http

apache

etag

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

like image 202
Chris Bartow Avatar asked Sep 04 '08 23:09

Chris Bartow


1 Answers

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)));
like image 80
Chris Bartow Avatar answered Sep 18 '22 05:09

Chris Bartow