homepage Welcome to WebmasterWorld Guest from 54.161.236.92
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
If-Modified-Since - Internal 500 error
phred




msg:3662377
 10:45 pm on May 29, 2008 (gmt 0)

Hi,

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

 

jdMorgan




msg:3662406
 11:27 pm on May 29, 2008 (gmt 0)

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.

Then it sounds to me as if you're looking in the wrong place. 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?

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

phred




msg:3662414
 11:53 pm on May 29, 2008 (gmt 0)

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

phred




msg:3662417
 12:03 am on May 30, 2008 (gmt 0)

Ahhh,, wait, wait. I see what you are asking. I need a rewrite rule to handle HTTP_IF_MODIFIED_SINCE.

I'll go chase that up now.

Phred

jdMorgan




msg:3662437
 12:42 am on May 30, 2008 (gmt 0)

Here's a quick over-view of the process:

  • The client requests a resource (a file, if you like) for the first time.
  • The server (or a script) checks the time that the resource was last modified, and sends a Last-Modified header, along with the requested content-body, stating when the resource was last modified (for example, the file creation or last-modification date).
  • The client caches both the content-body, and the headers in its cache.
  • The client, at its option, may send a conditional GET when requesting this resource the next time, stating "GET If-Modified-Since, along with the last-modified date that it received in the header the last time it requested the resource.
  • If the date in the If-Modified-Since header received from the client in older than the current last-modified date of the resource, the server should send the new version of the content, along with an updated Last-Modified header.
  • If not, then the server simply responds with a 304-Not Modified header, and does not send the content, thus saving server bandwidth. The client then knows that it can serve the content from its own cache, saving transfer time.

    Jim

  • phred




    msg:3662641
     8:19 am on May 30, 2008 (gmt 0)

    Hi 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

    jdMorgan




    msg:3662923
     3:45 pm on May 30, 2008 (gmt 0)

    I'm not sure what the point is, if you're going to ignore the IF-Modified-Since header and never send a 304.

    As to the 500-Error, you've got to get to the server error logs or log the PHP errors to find the problem. It could be caused by hundreds of things. :(

    Jim

    phred




    msg:3663312
     11:00 pm on May 30, 2008 (gmt 0)

    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

    jdMorgan




    msg:3663336
     11:45 pm on May 30, 2008 (gmt 0)

    Very strange! I wonder if they've got a caching system 'overlaid' on all user accounts. I don't see how the server would care, otherwise. I suppose you could 'touch' the requested file, so that its last-modified date would always be the time of the current request, and therefore avoid getting kicked for not sending a 304.

    Jim

    Global Options:
     top home search open messages active posts  
     

    Home / Forums Index / Code, Content, and Presentation / Apache Web Server
    rss feed

    All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
    Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
    WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
    © Webmaster World 1996-2014 all rights reserved