Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.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输出缓冲区压缩缓存输出_Php_Html_Caching_Output Buffering_Ob Start - Fatal编程技术网

使用PHP输出缓冲区压缩缓存输出

使用PHP输出缓冲区压缩缓存输出,php,html,caching,output-buffering,ob-start,Php,Html,Caching,Output Buffering,Ob Start,通过使用这一行代码ob_start('ob_gzhandler')

通过使用这一行代码
ob_start('ob_gzhandler')
$id = $_GET["id"];
$cachefile ="cache/p_{$id}.html";
if (file_exists($cachefile)) {
 include($cachefile);
 echo "<!-- Cached ".date('jS F Y H:i', filemtime($cachefile))." -->";
 exit;
}
ob_start('ob_gzhandler');

$fp = fopen($cachefile, 'w'); // open the cache file for writing
fwrite($fp, ob_get_contents()); // save the contents of output buffer to the file
fclose($fp); // close the file
ob_end_flush(); 
$id=$\u GET[“id”];
$cachefile=“cache/p{$id}.html”;
如果(文件_存在($cachefile)){
包括($cachefile);
回声“;
出口
}
ob_start('ob_gzhandler');
$fp=fopen($cachefile,'w');//打开缓存文件进行写入
fwrite($fp,ob_get_contents());//将输出缓冲区的内容保存到文件中
fclose($fp);//关闭文件
ob_end_flush();

服务器未对缓存文件进行gzip处理,请尝试以下方法:

ob_start('ob_gzhandler');
$id=$_GET[“id”];
$cachefile=“cache/p{$id}.html”;
如果(文件_存在($cachefile)){
包括($cachefile);
回声“;
}否则{
//你的html或其他东西。。。
$fp=fopen($cachefile,'w');//打开缓存文件进行写入
fwrite($fp,ob_get_contents());//将输出缓冲区的内容保存到文件中
fclose($fp);//关闭文件
}
ob_end_flush();

p、 我会把压缩任务留给web服务器(,)。

@RedGiant:或者像你建议的那样保存已经压缩的文件。这完全取决于你的需要。现在,当您保存了gzip缓存文件时,必须将encoding设置为gzip,以便浏览器知道数据是什么:
如果(file_存在($cachefile)){header('Content-encoding:gzip');…