In some cases my PHP script is providing a large binary file. I want to support the if-modified-since header.
During my tests I observed unexpected behaviour: If I set the last-modified response header in PHP then Apache seems to handle requests with if-modified-since header automatically ('200 OK' + content or '304 Not Modified' without content). It even overrules '200 OK' in header("Last-Modified: $lastModifiedValue GMT", true, 200);
.
I tried to find documentation about this behaviour before deciding if I rely on it or if I should implement a if(isset($headers['If-Modified-Since'])){...}
block.
Any experience, advice or hint about how official this behaviour is will be very welcome.
Full test snippet:
$lastModifiedValue = gmdate('D, d M Y H:i:s', filemtime($path));
header('Content-Type: application/octet-stream');
header("Last-Modified: $lastModifiedValue GMT", true, 200);
header('Content-Length: ' . filesize($path));
header('Content-Disposition: attachment; filename="binary-data.bin"');
ob_end_clean();
$fileHandle = fopen($path, "rb");
fpassthru($fileHandle);
fclose($fileHandle);
exit;
(Server runs on Apache: 2.2, PHP: 5.6)