Forum Moderators: phranque
I’m trying to serve a .txt file through php.
<?php
header("Content-type: text/plain");
works just fine.
<?php
header('Last-Modified: '.gmdate('D, d M Y H:i:s',filemtime('phred.txt')).' GMT');
header("Content-type: text/plain");
Serves the initial page request with Last-Modified header just fine. The next request then asks If-Modified-Since and the result is an Internal Error 500.
The shared server where the page is hosted has php/cgi implemented and ForceType doesn’t work. The only way I’ve found to get a .txt file sent to php is with a rewrite rule:
RewriteRule phred.txt$ phred.g.php [L,NC]
I’m stumped and don't have much hair remaining. Can anyone please help?
TIA,
Phred
Serves the initial page request with Last-Modified header just fine. The next request then asks If-Modified-Since and the result is an Internal Error 500.
What is in your server error log?
I should also point out that the scope of this forum does not include PHP coding, but until we establish the problem and determine whether it has to do with your server configuration, we'll let that slide...
Jim
Where is the logic that checks the incoming If-Modified-Since header date/time from the client against the last-modified time of the content and decides whether to re-send the content or reply with a 304-Not Modified response?
Good question - I’m in way over my head here. Let’s say I do nothing and let Apache just serve a .txt file as text. Doesn’t Apache add the Last-Modified header and doesn’t Apache then check incoming If-Modified and send a 304 if appropriate?
What is in your server error log?
No errors in the server error log.
I should also point out that the scope of this forum does not include PHP coding
Sorry, was only trying to show the headers. I can post the captured output from Live HTTP Headers if you would like.
Cheers,
Phred
Jim
Thanks for the over-view.
After several hours researching, trying various alternatives, think it has come down to basically this:
In response to an If-Modified-Since, if the file has been modified what headers should be sent? From what I can determine they would be the same headers that were initially sent to the browser before the local caching that resulted from the initial Last-Modified header. Nothing special in reply to If-Modified-Since, just a normal full serve 200. Is that correct? Even if the file hasn’t been modified I should be able to ignore the If-Modified, skipping any benefit from reduced output of 304 processing, and just re-serve the file. Yes? Captured from Live HTTP Headers:
. First request
hxxp://www.yyy.com/phred.txt
GET /phred.txt HTTP/1.1
Host: www.yyy.com
User-Agent stuff
Accept stuff
Keep-Alive: 300
Connection: keep-alive
And I serve:
HTTP/1.x 200 OK
Date: Thu, 29 May 2008 21:46:49 GMT
Server: Apache/2.2.6 (Win32)
Last-Modified: Thu, 29 May 2008 11:48:18 GMT <---<<
Accept-Ranges: bytes <---<<
Content-Length: 202
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/plain <---<<
X-Pad: avoid browser bug
. Second request - hitting browser refresh
hxxp://www.yyy.com/phred.txt
GET /phred.txt HTTP/1.1
Host: www.yyy.com
User-Agent:
Accept:
Keep-Alive: 300
Connection: keep-alive
If-Modified-Since: Thu, 29 May 2008 11:48:18 GMT
Cache-Control: max-age=0
And if modified I serve:
HTTP/1.x 200 OK
Date: Thu, 29 May 2008 21:46:53 GMT
Server: Apache/2.2.6 (Win32)
Last-Modified: Thu, 29 May 2008 11:48:18 GMT <---<<
Accept-Ranges: bytes <---<<
Content-Length: 202
Keep-Alive: timeout=5, max=98
Connection: Keep-Alive
Content-Type: text/plain <---<<
Here’s the problem. This works just fine on my local WAMP test system (that's where the Live HTTP Headers came from) but I get the Internal 500 error on the shared hosting environment.
So, I’m confused.
Phred
I'm not sure what the point is, if you're going to ignore the IF-Modified-Since header and never send a 304.
The primary reason for sending Last-Modified is to make the resulting output stream look identical to the browser whether the .txt file is served directly by Apache or via a php script. From what I can determine (and what I see with Live Headers) the default behavior is for Apache to send Last-Modified headers when serving .txt files, so that's what I wanted to emulate.
As to the 500-Error, you've got to get to the server error logs or log the PHP errors to find the problem.
As they say, bugger - no errors in the hosting site server error log,, however,, solved the problem. It appears that on the shared server system if an If-Modified-Since header is received and the file is not modified you can’t send anything other than headers else you get a 500 error. Probably has something to do with Last-Modified header being sent in response to If-Modified having same dates. Basically it appears you are forced to do proper 304 processing. That’s not how my WAMP test system behaves but hey, when in Rome..
Thanks for your help.
Cheers,
Phred
Jim