Php Cloudflare内容类型

Php Cloudflare内容类型,php,web,cloudflare,content-length,http-content-length,Php,Web,Cloudflare,Content Length,Http Content Length,我刚刚开始使用CloudFlare,它的CDN服务出现了问题。我希望我的脚本将内容类型标题发送回。我尝试过使用页面规则,但一点帮助也没有。我只想得到内容的长度 PHP脚本: <?php ob_start(); ob_start('ob_gzhandler'); $file = $_SERVER['DOCUMENT_ROOT'] . "/MyPath.txt"; //Path to your *.txt file $contents = file($fil

我刚刚开始使用CloudFlare,它的CDN服务出现了问题。我希望我的脚本将内容类型标题发送回。我尝试过使用页面规则,但一点帮助也没有。我只想得到内容的长度

PHP脚本:

<?php
    ob_start();
    ob_start('ob_gzhandler');

    $file = $_SERVER['DOCUMENT_ROOT'] . "/MyPath.txt"; //Path to your *.txt file 
    $contents = file($file); 
    $string = implode($contents); 
    echo $string;
    ob_end_flush();  // The ob_gzhandler one
    header('Content-Length: '.ob_get_length());
    ob_end_flush();  // The main one

?>
本地主机头:

HTTP/1.1 200 OK
Date: Wed, 19 Aug 2015 17:39:10 GMT
Server: Apache/2.4.9 (Win64) PHP/5.5.12
X-Powered-By: PHP/5.5.12
Set-Cookie: PHPSESSID=s3hdkbh4vd2rj5ieqocafebju6; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Vary: Accept-Encoding
Content-Length: 135680
Connection: close
Content-Type: text/html

您需要添加文件扩展名以便缓存脚本的输出,或者使用页面规则强制缓存资源。这将导致不使用分块编码发送文件,这将启用内容长度头

从:

解决方案/解决方法-如果您向资源添加文件扩展名,使其与我们支持的文件扩展名列表匹配,那么CloudFlare的系统将使用内容长度头发送该文件,只要您还将HTTP 1.0作为协议发送

或者,您可以使用PageRule并使用“自定义缓存”选项选择“缓存所有内容”,这将强制我们的系统进行缓存,即使它没有我们常用的文件扩展名——在这种情况下,内容长度也将保留


我已经厌倦了为脚本和内容设置适当的规则,但它仍然没有发送内容长度。我还尝试发送我的请求HTTP 1.0@user3732111您是否正在向php脚本发送GET参数?如果是这样,您需要在页面规则中对其进行模式匹配,例如
http://example.com/test.php*
。我已将其添加到模式中,但仍然不起作用。我已在其他不需要参数且cloudflare不会显示内容长度的脚本上对此进行了测试。我不确定我的设置是否正确。
HTTP/1.1 200 OK
Date: Wed, 19 Aug 2015 17:39:10 GMT
Server: Apache/2.4.9 (Win64) PHP/5.5.12
X-Powered-By: PHP/5.5.12
Set-Cookie: PHPSESSID=s3hdkbh4vd2rj5ieqocafebju6; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Vary: Accept-Encoding
Content-Length: 135680
Connection: close
Content-Type: text/html