使用 php4 加速 web 传输

2016-01-29 14:45 6 1 收藏

使用 php4 加速 web 传输,使用 php4 加速 web 传输

【 tulaoshi.com - PHP 】

  <?
/***************************************
** 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<brn";
}
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;
}
}
?




 

来源:https://www.tulaoshi.com/n/20160129/1494132.html

延伸阅读
标签: Web开发
一、 摘要 本文简单阐述了 Proxy 模式及具体说明了如何在 PHP4 中实现动态代理,本文只是给出了一个实现的方法的原型。由于水平有限,有任何意见和建议请反馈给 Binzy [ Binzy at JustDN dot Com ]。 二、 概述 在我们开始实现 Dynamic Proxy 之前,也许我们应该先了解一下什么是 Proxy 和它有什么用。下面是一篇来自博客堂...
标签: PHP
       PHP4中的SESSION管理   作者: Mattias Nilsson   --------------------------------------------------------------------------------      PHP4的新特性中最引人注目就是对SESSION的管理功能.当别人访问你的站点时,你可以把变量保存到SESSION对象中,...
标签: PHP
作者:Binzy 来源:超越PHP 一、 摘要 本文简单阐述了Proxy模式及具体说明了如何在PHP4中实现动态代理, 本文只是给出了一个实现的方法的原型. 由于水平有限, 有任何意见和建议请反馈给Binzy [ Binzy at JustDN dot Com ]. 二、 概述 在我们开始实现Dynamic Proxy之前, 也许我们应该先了解一下什么是Proxy和它有什么用. 下面是一...
标签: PHP
  在Windosws 2000 Server 上用PHP4访问Oracle815     系统环境:   1、操作系统:Windows 2000 Server 2、数据库: Oracle 8i R2 (8.1.6) for NT 企业版 3、安装路径:D:ORACLE 安装配置PHP4:   第一步,解开php-4.0.3-Win32.zip压缩包,把它放在C:PHP下面。 第二步,把C:PHP下面的php.ini-...
标签: PHP
现在给你揭开迷团的另一半-"login.php" 脚本文件。如果不出意外,这个脚本将接受输入的名字,检查是否用户存在,决定是允许还是拒绝进入站点。由于你还没学到PHP的条件语句和逻辑处理,我们现在不打算给你论证清楚-相反,我们仅仅给你展示在前面表单里提交的数据是如何被传送到 "login.php",并能被这个文...

经验教程

175

收藏

80
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部