Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 配置无cookieless域以提供静态内容的方法是什么?_Php_Apache_.htaccess_Mod Rewrite_Cookies - Fatal编程技术网

Php 配置无cookieless域以提供静态内容的方法是什么?

Php 配置无cookieless域以提供静态内容的方法是什么?,php,apache,.htaccess,mod-rewrite,cookies,Php,Apache,.htaccess,Mod Rewrite,Cookies,我试图从一个没有Cookie的域中提供静态内容。为此,我创建了一个单独的域,而不是一个带有CNAME设置的子域,等等,并创建了一个简单的PHP文件,用于测试抓取图像文件的检索时间差异,在本例中,相同的图像重复10000次: <?php echo '<!DOCTYPE html>'; // Here I can toggle between grabbing the static content from the static domain with the specially

我试图从一个没有Cookie的域中提供静态内容。为此,我创建了一个单独的域,而不是一个带有CNAME设置的子域,等等,并创建了一个简单的PHP文件,用于测试抓取图像文件的检索时间差异,在本例中,相同的图像重复10000次:

<?php
echo '<!DOCTYPE html>';
// Here I can toggle between grabbing the static content from the static domain with the specially edited .htaccess file, or from the main domain, just by remming out one line and unremming the other:
$source = "http://MY-STATIC-DOMAIN.com/";
//$source = "http://MY-DYNAMIC-DOMAIN.COM/"

$before = microtime(true);
$output = '<img style="display: none;" src="' . $source  . 'images/TEST-IMAGE.jpeg "  height="400" width="311"/>';

for ($i=0 ; $i<10000 ; $i++) {
    echo $output;
}

$after = microtime(true);
$timex = ($after-$before);
echo $timex;
?>
…对于弯曲复杂的心灵:

# Use Mod_deflate to compress static files
<ifmodule mod_deflate.c>
    <filesmatch ".(js|css|ico|txt|htm|html|php)$">
        SetOutputFilter DEFLATE
    </filesmatch>
</ifmodule>

# Speed up caching
FileETag MTime Size

# Expires
ExpiresActive On
ExpiresDefault "access plus 366 days"

# Future Expires Headers
<filesmatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
    Header set Expires "Sat, 27 Dec 2014 23:59:59 GMT"
</filesmatch>
然而,无论我将哪些指令放入静态域的.htaccess文件中(该文件包含我在测试中反复调用的JPEG文件),时间差都是可以忽略的,在某些情况下,从源/动态站点检索静态内容的速度更快

我是否错误地设计了测试文件?或者有没有一套.htaccess指令比上面两个相互竞争的指令更好,我还找到了其他指令……我已经在本地服务器和实时站点上测试了几个小时了

我还读过一份研究报告,其中似乎证明了从主域本身提供缩小的.CSS文件比从静态域检索它们要快,但作者在文章的结论中承认,图像仍然最好从静态域提供:


非常感谢任何能够为我指明正确方向的大师,特别是在一开始就不发送带有内容请求的cookie方面,我认为这将受益于HTML中的一个内嵌命令。

好吧,如果您想要性能,最好使用Nginx而不是Apache。另外,如果您只想提供静态文件,那么您应该缩小css和js内容,并使用适当的Expires/Cache控制头提供它们,尽管您不应该将其设置得太高。7天就够了。如果我是你,我就不会太担心时差了。尽管你的测试脚本有缺陷。您所做的可能是第10000次输出图像标记,但浏览器仍将只加载一次,因为它是同一图像。不,图像检索10000次,加载10000次。证据来自不同版本的脚本,该脚本捕获了1000个不同的图像,这比重复检索同一图像花费的时间要少得多。无论如何,浏览器怎么能一次又一次地知道它是同一个图像呢?它对此并不了解……它只是执行传递给它的命令。我知道关于minify的部分,并在我的帖子中对此进行了评论。我需要一个检索图像的方法,不发送或接收cookie。
# Use Mod_deflate to compress static files
<ifmodule mod_deflate.c>
    <filesmatch ".(js|css|ico|txt|htm|html|php)$">
        SetOutputFilter DEFLATE
    </filesmatch>
</ifmodule>

# Speed up caching
FileETag MTime Size

# Expires
ExpiresActive On
ExpiresDefault "access plus 366 days"

# Future Expires Headers
<filesmatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
    Header set Expires "Sat, 27 Dec 2014 23:59:59 GMT"
</filesmatch>