为什么 PHP 在缓存时区分 .php 和 .abc 扩展名?
PHP 引擎处理仅文件扩展名不同的相同文件的方式似乎存在问题。
问题:“If-Modified-Since 条件请求返回的完整内容未更改。”
另外,我测量到 .php 扩展名的加载速度比具有 .xxx 扩展名的同卵双胞胎要快得多,即使文件内容是相同,它们仅在文件扩展名上有所不同。
“HTTP 允许客户端 有条件请求查看是否有副本 他们所持有的观点仍然有效。自从 该响应有一个“最后修改时间” 标头,客户端应该能够使用 If-Modified-Since 请求标头 用于验证。 RED 已经做到了这一点并且 发现资源发送了完整的 尽管没有回应 改变了,说明没有 支持上次修改验证。”
主页以 .php
结尾
完全相同的文件,但是结尾 .ast
给定:
一个 home.php 文件被复制为 home.xxx ,并将此扩展名添加到 htaccess 以将其识别为 PHP 文件。 .php 文件侦听 php.ini,其中新鲜度设置为 3 小时,非 .php 文件必须侦听 htaccess,其中。新鲜度设置为 2 小时,根据:
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>
到目前为止,一切都很好,除了非 php 文件没有正确缓存,或者它缓存得很好,但没有很好地验证,更具体地说,请参阅随附的图像。只有非 php 文件扩展名会导致错误并且加载速度较慢,
因为其中的所有元素都会从缓存中正确加载,而 page.abc 会返回完整的请求。缓存,意味着整个页面速度变慢
:为了消除返回完整内容不变的 If-Modified-Since 条件请求,应该更改什么?
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.
"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
exact same file, but ending .ast
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)quot;>
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的服务器似乎无法确定如何解码扩展名,因为它不是 .php。即使您在 httpaccess 中将扩展名定义为 php,服务器仍然需要一些额外的步骤来处理页面,这意味着它总是比仅使用 .php 花费更长的时间(尽管应该只有几毫秒的差异) ,很可能是服务器问题导致这需要更长的时间)。为什么不在您的页面上使用 .php 扩展名呢?为什么需要 .abc?最好只使用默认扩展名而不是屏蔽它。
编辑:将此功能放在每个页面的顶部,它将检测用户所在的域名,去除 www 和域名扩展名,然后仅显示该特定域名的内容。您可以对每个域名使用相同的 .php 文件,而不必执行任何时髦的扩展。
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.