动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   PHP → 阅读文章

 使用php 4加速web传输

作者来源: 
阅读 1037 人次 , 2006-3-29 4:10:00 


<?
/***************************************
** title.........: php4 http compression speeds up the web
** version.......: 1.10
** author........: catoc <catoc@163.net>
** filename......: gzdoc.php
** last changed..: 25/08/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) <catoc@163.net>
**  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.
** useage........:
**  no space before the beginning of the first '<?' tag.
**  ------------start of file----------
**  |<?
**  | include('gzdoc.php');
**  | print "start output !!";
**  |?>
**  |<html>
**  |... the page ...
**  |</html>
**  |<?
**  | gzdocout();
**  |?>
**  -------------end of file-----------
***************************************/
ob_start();
ob_implicit_flush(0);
function getheader(){
$headers = getallheaders();
while (list($header, $value) = each($headers)) {
$message .= "$header: $value<br>\n";
}
return $message;
}
function checkcangzip(){
global $http_accept_encoding, $php_self, $wget, $remote_addr, $s_username;
if (connection_timeout() || connection_aborted()){
return 0;
}
if ((strpos('catoc'.$http_accept_encoding, 'gzip')) || $wget == 'y'){
if (strpos('catoc'.$http_accept_encoding, 'x-gzip')){
$encoding = "x-gzip";
$error_msg = str_replace('<br>','',getheader());
$error_msg .= "time: ".date("y-m-d h:i:s")."\n";
$error_msg .= "remote-address: ".$remote_addr."\n";
//mail('your@none.net', "user have x-gzip output in file $php_self!!!", $error_msg);
}else{
$encoding = "gzip";
}
return $encoding;
}else{
return 0;
}
}
function gzdocout(){
global $php_self, $catocgz, $remote_addr, $s_username;
$encoding = checkcangzip();
if ($encoding){
print "\n<!-- use compress $encoding -->\n";
$contents = ob_get_contents();
ob_end_clean();
if ($catocgz == 'y'){
print "not compress lenth: ".strlen($contents)."<br>";
print "compressed lenth: ".strlen(gzcompress($contents))."<br>";
exit;
}else{
header("content-encoding: $encoding");
}
print pack('cccccccc',0x1f,0x8b,0x08,0x00,0x00,0x00,0x00,0x00);
$size = strlen($contents);
$crc = crc32($contents);
$contents = gzcompress($contents);
$contents = substr($contents, 0, strlen($contents) - 4);
print $contents;
print pack('v',$crc);
print pack('v',$size);
exit;
}else{
ob_end_flush();
$error_msg = str_replace('<br>','',getheader());
$error_msg .= "time: ".date("y-m-d h:i:s")."\n";
$error_msg .= "remote-address: ".$remote_addr."\n";
//mail('your@none.net', "user can not use gzip output in file $php_self!!!", $error_msg);
exit;
}
}
?> 

 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:有一个类可以统计脚本执行时间
· 下一篇:关于输出缓冲的讨论
· PHP4实际应用经验篇(3)
· apache服务器专用函数库
· PHP4实际应用经验篇(1)
· 一个模仿oso的论坛程序(之一)
· 十天学会php之第一天


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077