如何用PHP控制浏览器cache(4)_PHP教程

编辑Tag赚U币
教程Tag:暂无Tag,欢迎添加,赚取U币!

推荐:解读使用PHP4.2.0及以后版本的注意事项
从PHP 4.2.0版本开始中, PHP 指令 register_globals 的默认值为 off(在php.ini配置文件里). 这是 PHP 的一个主要变化。register_globals是干什么用的呢?它是PHP用来控制是否将EGPCS (Env

以下为引用的内容:

Example 6. 加快传输

/*
** Title.........: PHP4 HTTP Compression Speeds up the Web
** Version.......: 1.20
** Author........: catoc
** Filename......: gzdoc.php
** Last changed..: 18/10/2000
** Requirments...: PHP4 >= 4.0.1
** PHP was configured with --with-zlib[=DIR]
** Notes.........: Dynamic Content Acceleration compresses
** the data transmission data on the fly
** code by sun jin hu (catoc)
** Most newer browsers since 1998/1999 have
** been equipped to support the HTTP 1.1
** standard known as "content-encoding."
** Essentially the browser indicates to the
** server that it can accept "content encoding"
** and if the server is capable it will then
** compress the data and transmit it. The
** browser decompresses it and then renders
** the page.
**
** Modified by John Lim (jlim@natsoft.com.my)
** based on ideas by Sandy McArthur, Jr
** Usage........:
** No space before the beginning of the first ' ** ------------Start of file---------
-
** │ ** │ include('gzdoc.php');
** │? >
** │
** │... the page ...
** │
** │ ** │ gzdocout();
** │? >
** -------------End of file-----------
*/
ob_start();
ob_implicit_flush(0);
function CheckCanGzip(){
global HTTP_ACCEPT_ENCODING;
if (headers_sent() ││ connection_timeout() ││ connection_aborted()){
return 0;
}
if (strpos(HTTP_ACCEPT_ENCODING, 'x-gzip') !== false) return "x-gzip";
if (strpos(HTTP_ACCEPT_ENCODING,'gzip') !== false) return "gzip";
return 0;
}
/* level = compression level 0-9, 0=none, 9=max */
function GzDocOut(level=1,debug=0){
ENCODING = CheckCanGzip();
if (ENCODING){
print "\n\n";
Contents = ob_get_contents();
ob_end_clean();
if (debug){
s = "

Not compress length: ".strlen(Contents);
s .= "
Compressed length: ".strlen(gzcompress(Contents,level));
Contents .= s;
}
header("Content-Encoding: ENCODING");
print "\x1f\x8b\x08\x00\x00\x00\x00\x00";
Size = strlen(Contents);
Crc = crc32(Contents);
Contents = gzcompress(Contents,level);
Contents = substr(Contents, 0, strlen(Contents) - 4);
print Contents;
print pack('V',Crc);
print pack('V',Size);
exit;
}else{
ob_end_flush();
exit;
}
}
?>

这是catoc的一段很早以前的代码,是在weblogs.com看到的,他利用了zlib的函数,对传输的内
容进行了压缩,测试表明,对于10k以上的页面,会产生效果,而且页面越大,效果越明显。

分享:浅析PHP4和PHP5的配置的异同
配置php4或者php5的过程中,php4,5的配置的步骤大致一样的,但是配置内容有一些差别。在LINUX等环境下编译,一般来说,只要编译的选项正确,配置也就正确了;在windows配置则需要注意以下

共4页上一页1234下一页
来源:模板无忧//所属分类:PHP教程/更新时间:2008-12-01
相关PHP教程