apache - Caching image requests through PHP - If-Modified-Since not being sent -
I am serving images via PHP and to respond to 304 headers to save load problems, There are some problems in setting up.
Most of the code given below is found on php.net. It works, but always responds with 200. If-Modified-For Any reason- Because the header is not being received on any request, I am sending the final revised header. Any Apache server being done on this could be a wrong idea?
This page will load the image from the disk and will finally display it in the browser, with the modified header sent. If you refresh the page, then the browser does not send an F-Moded-header like it should. Define
('SITEPATH', (dirname ($ _ SERVER ['SCRIPT_NAME'] == '/')? '/': Dirname ($ _ SERVER ['SCRIPT_NAME'] ). '/'); $ Load_path = $ _SERVER ['DOCUMENT_ROOT'] Sitepath 'Fpo_image.jpg'; // Get the header sent by the customer $ header = apache_request_headers (); $ File_time = filemtime ($ load_path); Header ('cache-control: required-modified'); Header ('Last-Modified:'. GMDATE ('D, DM YH: I: S', $ file_time). 'GMT'); If (isset ($ headers ['if-modified-since']) & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp ;-in-find- ('if-modified-' ')) == $ file_time) {header (' http / 1.1 Header ('content-length:'. Files ($ load_path); header ('content'); header ('connection: closed');} and {header ('http / 1.1 200 right) Type: image / jpeg '); readfile ($ load_path);}
I believe Is that it should be
if (Isset ($ headers ['if-modified-since']) & amp; (strtotime ($ headers ['if-modified-since'] }> = $ File_time)) {
Checking that the revised time is not just equal Equal. Although I understand both values must should be the same.
Comments
Post a Comment