Why is PHP discriminating between .php and .abc extensions for caching?
Asked Answered
S

1

9

There seems to be a problem between how PHP engine handles identical files that differ only in their file extension.

Problem: "An If-Modified-Since conditional request returned the full content unchanged."

Also, I measured that the .php extension loads much faster than identitcal twin with .xxx extension even though the file contents are identical, and they differ only in their file extension.

alt text

alt text

"HTTP allows clients to make conditional requests to see if a copy that they hold is still valid. Since this response has a Last-Modified header, clients should be able to use an If-Modified-Since request header for validation. RED has done this and found that the resource sends a full response even though it hadn't changed, indicating that it doesn't support Last-Modified validation."


homepage ending with .php

alt text


exact same file, but ending .ast

alt text


Given:

A home.php file is copied as home.xxx and this extension is added to htaccess to recognize it as a PHP file. The .php file listen to the php.ini where freshness is set to 3 hrs, the non .php files have to listen to htaccess where freshness is set to 2 hrs according to:

AddType application/x-httpd-php .php .ast .abc .xxx .etc

<IfModule mod_headers.c>
    ExpiresActive On
    ExpiresDefault M2419200
    Header unset ETag
    FileETag None
    Header unset Pragma
    Header set Cache-Control "max-age=2419200"

    ##### DYNAMIC PAGES
    <FilesMatch "\\.(ast|php|abc|xxx)$">
        ExpiresDefault M7200
        Header set Cache-Control "public, max-age=7200"
    </FilesMatch>
</IfModule>

So far so good and everything loads, except, the non-php file doesn't cache properly, or it does cache well but doesn't validate well, to be more specific. See images enclosed. Only the non-php file extension causes the error and loads slower.

The entire page.php loads faster as somehow all the elements in there then load properly from cache, while the page.abc has the full request returned while it ought to be cached, meaning the entire page is slower.

Bottom line: What should be changed, in order eliminate the If-Modified-Since conditional request returning the full content unchanged?

Shoddy answered 21/12, 2010 at 19:16 Comment(9)
do you expose a php extension to the client? what a rare behavior!Feigned
@Col. Shrapnlel:Thanks for quick comment! You mean the header that RED examnied are not being sent to them in reality? what do you mean by exposing the php extention to the client? where can i check if this is true or false in my case?Shoddy
Well dnnno for the xxx extension, but for php scripts you have to implement conditional get programmaticallyFeigned
file changes doesn't matter for the dynamically generated content. I suppose your problem is host-related. I suppose it is some sort of shared hosting you are using?Feigned
just updated my question with highly detailed picture that are very important in this matter! (but why are they small and not clickable to become big??)Shoddy
I hate such lame pictures with ugly handmade captions. May be someone consider it funny but in fact it's just ugly. It says most time were spend in the queue. What's that queue?Feigned
Oh look, more freehand circles. There's even a dotted one!Geo
meh.. its the Laundry guy again with screencapsWhiteley
Thanks for support @Geo and others, keeps my spirit fueled. If i only knew how to take away the differences between .php and any other valid three char-extension, i would be in near PARADISE, hence am giving my BOUNTY to the 1st person here who SOLVES the riddle!Shoddy
A
2

It seems like your server is having trouble determining how to decode the extension, since it is not .php. Even if you defined the extension to be recognized as php in your httpacess, it still requires some extra steps for the server to process the page, meaning it will always take longer then just using .php (although it should only be a few ms difference, most likely a server problem is causing this to take much longer). Why not just use the .php extension on your pages? Why do you need .abc? It's always best to just use the default extension instead of masking it.

EDIT: Put this function on the top of each page, it will detect what domain name the user is on, strip the www and domain extension and then display content for that specific domain name only. You can use the same .php file for every domain name and don't have to do any funky extensions.

<?php
$domain = explode(".", $_SERVER['SERVER_NAME']);
if ($domain[2]) {
    $domainName = $domain[1];
}
else {
    $domainName = $domain[0];
}

if ($domainName = "YourDomainNameWithNoExtension") {
    echo "Welcome to $domainName";
}
?>
Aspirant answered 21/12, 2010 at 20:40 Comment(4)
Thanks very much for constructive, meaningful and useful direction Kp! Indeed, everything else is exactly the same, except the changed three letter extension NOT being default .php Apparently there is a penalty that is deeply hidden and not easily fixed ( the emptyness of constructive, usefull answers proves unfortunaly this ) The reason why we have to use these extensions, is becaouse using mutliple domainaliases all going to same root. Each can have their own same-name pages e.g. ABC.com >> contact.abc XYZ.com >> contact.xyz etc all Best kept in Root, in our situation... ideas?Shoddy
@Shoddy That's a pretty terrible reason to use different file extensions. Why doesn't each site have it's own directory, rather than dumping all the files into one directory? That sounds like an organizational nightmare.Diadelphous
Put this function on the top of each page, it will detect what domain name the use is on and then it displays content for that specific domain name only. You can use the same .php file for every domain name and don't have to do any funky extensions.Aspirant
<?php $domain = explode(".", $_SERVER['SERVER_NAME']); if ($domain[2]) { $domainName = $domain[1]; } else { $domainName = $domain[0]; } if ($domainName = "YourDomainNameWithNoExtension") { echo "Welcome to $domainName"; } ?>Aspirant

© 2022 - 2024 — McMap. All rights reserved.