为什么 PHP 在缓存时区分 .php 和 .abc 扩展名?

发布于 2024-10-08 08:59:34 字数 1498 浏览 7 评论 0原文

PHP 引擎处理仅文件扩展名不同的相同文件的方式似乎存在问题。

问题:“If-Modified-Since 条件请求返回的完整内容未更改。”

另外,我测量到 .php 扩展名的加载速度比具有 .xxx 扩展名的同卵双胞胎要快得多,即使文件内容是相同,它们仅在文件扩展名上有所不同。

替代文本

“HTTP 允许客户端 有条件请求查看是否有副本 他们所持有的观点仍然有效。自从 该响应有一个“最后修改时间” 标头,客户端应该能够使用 If-Modified-Since 请求标头 用于验证。 RED 已经做到了这一点并且 发现资源发送了完整的 尽管没有回应 改变了,说明没有 支持上次修改验证。”


主页以 .php 结尾

alt text


完全相同的文件,但是结尾 .ast

alt text


给定:

一个 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.

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)
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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

老娘不死你永远是小三 2024-10-15 08:59:34

您的服务器似乎无法确定如何解码扩展名,因为它不是 .php。即使您在 httpaccess 中将扩展名定义为 php,服务器仍然需要一些额外的步骤来处理页面,这意味着它总是比仅使用 .php 花费更长的时间(尽管应该只有几毫秒的差异) ,很可能是服务器问题导致这需要更长的时间)。为什么不在您的页面上使用 .php 扩展名呢?为什么需要 .abc?最好只使用默认扩展名而不是屏蔽它。

编辑:将此功能放在每个页面的顶部,它将检测用户所在的域名,去除 www 和域名扩展名,然后仅显示该特定域名的内容。您可以对每个域名使用相同的 .php 文件,而不必执行任何时髦的扩展。

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

if ($domainName = "YourDomainNameWithNoExtension") {
    echo "Welcome to $domainName";
}
?>

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";
}
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文