Forum Moderators: coopster

Message Too Old, No Replies

Caching of files served by ReadFile(): headers not being sent?

         

Vector

10:24 pm on Nov 23, 2009 (gmt 0)

10+ Year Member



I'm serving VERY large image files, and mp3s, for a band who's on my servers, and fairly popular; which means that i'm about to get all of my bandwidth eaten.

I echoed apache_request_headers() and $_SERVER['HTTP_IF_MODIFIED_SINCE'], but the $_SERVER version is empty each time, and the apache_request_headers does not have the if-modified-since. I send these headers on the initial download, and if you click download again, there is no caching or if-modified. I also used tamper-data to watch the headers being sent (and received), and when the server is sending the headers, it is NOT sending the cache headers.

 $expires = 60*60*24*365;
$size = filesize("{$client_directory}/{$_GET['did']}");
header("Content-Length: ".$size,true);
header("Cache-Control: max-age={$expires}, public, no-transform",true);
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT',true);
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()-$expires) . ' GMT',true);
header("Content-type: audio/example");
header("Content-Disposition: attachment; filename=\"{$_GET['did']}\"");
readfile("{$client_directory}/{$_GET['did']}");

Any help is appreciated.

Vector

11:33 pm on Nov 23, 2009 (gmt 0)

10+ Year Member



Ok, i've got it sending the CORRECT cache headers now, but i am still not getting the "if-modified-since" header from the client.

Here's the client headers:

Host=example.com
User-Agent=Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.15) Gecko/2009102704 Fedora/3.0.15-1.fc10 Firefox/3.0.15
Accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language=en-us,en;q=0.5
Accept-Encoding=gzip,deflate
Accept-Charset=ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive=300
Connection=keep-alive
Referer=http://example.com/?a=WCMS_Page_Display&id=156008001258174118&t=6_-_C.O.M.A.
Cookie=ssssssssssssssssssssssssssssssss

and the server headers:

Status=OK - 200
Date=Mon, 23 Nov 2009 23:27:18 GMT
Server=Apache/2.2.11 (Fedora)
Content-Length=4400274
Cache-Control=max-age=31536000, public, no-transform
Expires=Tue, 23 Nov 2010 23:26:09 GMT
Last-Modified=Mon, 23 Nov 2009 23:26:09 GMT
Content-Disposition=attachment; filename="Coma.mp3"
Content-Encoding=gzip
Vary=Accept-Encoding
Keep-Alive=timeout=15, max=100
Connection=Keep-Alive
Content-Type=audio/example

But when i request the file over and over, the headers are the same. The client never sends the "if-modified-since" header, and so i can't tell if they've already downloaded it before so that i can send them the "not modified" header, instead of the file.

[edited by: coopster at 2:54 pm (utc) on Dec. 5, 2009]
[edit reason] please use example.com in code, thanks [/edit]

coopster

2:54 pm on Dec 5, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, Vector

The client may be configured to not send that particular header depending on browser and browser settings.