文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>使用php4加速web传输

使用php4加速web传输

时间:2007-02-17  来源:PHP爱好者

<?
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
/***************************************
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** Title.........: PHP4 HTTP Compression Speeds up the Web
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** Version.......: 1.10
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** Author........: catoc <[email protected]>
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** Filename......: gzdoc.php
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** Last changed..: 25/08/2000
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** Requirments...: PHP4 >= 4.0.1
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** PHP was configured with --with-zlib[=DIR]
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** Notes.........: Dynamic Content Acceleration compresses
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** the data transmission data on the fly
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** code by sun jin hu (catoc) <[email protected]>
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** Most newer browsers since 1998/1999 have
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** been equipped to support the HTTP 1.1
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** standard known as "content-encoding."
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** Essentially the browser indicates to the
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** server that it can accept "content encoding"
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** and if the server is capable it will then
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** compress the data and transmit it. The
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** browser decompresses it and then renders
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** the page.
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** Useage........:
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** No space before the beginning of the first '<?' tag.
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** ------------Start of file----------
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** |<?
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** | include('gzdoc.php');
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** | print "Start output !!";
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** |?>
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** |<HTML>
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** |... the page ...
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** |</HTML>
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** |<?
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** | gzdocout();
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** |?>
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
** -------------End of file-----------
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
***************************************/
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
ob_start();
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
ob_implicit_flush(0);
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
function GetHeader(){
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
$headers = getallheaders();
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
while (list($header, $value) = each($headers)) {
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
$Message .= "$header: $value<br>n";
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
}
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
return $Message;
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
}
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
function CheckCanGzip(){
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
global $HTTP_ACCEPT_ENCODING, $PHP_SELF, $Wget, $REMOTE_ADDR, $S_UserName;
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
if (connection_timeout() || connection_aborted()){
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
return 0;
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
}
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
if ((strpos('catoc'.$HTTP_ACCEPT_ENCODING, 'gzip')) || $Wget == 'Y'){
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
if (strpos('catoc'.$HTTP_ACCEPT_ENCODING, 'x-gzip')){
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
$ENCODING = "x-gzip";
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
$Error_Msg = str_replace('<br>','',GetHeader());
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
$Error_Msg .= "Time: ".date("Y-m-d H:i:s")."n";
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
$Error_Msg .= "Remote-Address: ".$REMOTE_ADDR."n";
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
//mail('[email protected]', "User have x-gzip output in file $PHP_SELF!!!", $Error_Msg);
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
}else{
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
$ENCODING = "gzip";
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
}
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
return $ENCODING;
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
}else{
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
return 0;
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
}
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
}
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
function GzDocOut(){
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
global $PHP_SELF, $CatocGz, $REMOTE_ADDR, $S_UserName;
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
$ENCODING = CheckCanGzip();
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
if ($ENCODING){
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
print "n<!-- Use compress $ENCODING -->n";
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
$Contents = ob_get_contents();
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
ob_end_clean();
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
if ($CatocGz == 'Y'){
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
print "Not compress lenth: ".strlen($Contents)."<BR>";
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
print "Compressed lenth: ".strlen(gzcompress($Contents))."<BR>";
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
exit;
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
}else{
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
header("Content-Encoding: $ENCODING");
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
}
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
print pack('cccccccc',0x1f,0x8b,0x08,0x00,0x00,0x00,0x00,0x00);
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
$Size = strlen($Contents);
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
$Crc = crc32($Contents);
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
$Contents = gzcompress($Contents);
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
$Contents = substr($Contents, 0, strlen($Contents) - 4);
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
print $Contents;
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
print pack('V',$Crc);
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
print pack('V',$Size);
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
exit;
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
}else{
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
ob_end_flush();
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
$Error_Msg = str_replace('<br>','',GetHeader());
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
$Error_Msg .= "Time: ".date("Y-m-d H:i:s")."n";
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
$Error_Msg .= "Remote-Address: ".$REMOTE_ADDR."n";
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
//mail('[email protected]', "User can not use gzip output in file $PHP_SELF!!!", $Error_Msg);
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
exit;
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
}
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
}
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
?>
c hina it power . c omt4CVPPhg6uiQsxsKAA5IiXG8I
php爱好者站 http://www.phpfans.net PHP|MySQL|javascript|ajax|html.
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载