当前位置: 首页 > 图文教程 > 网络编程 > PHP > 使用 php4 加速 web 传输

PHP
让我们来编写一些PHP实用的脚本
七种缓存使用武器 为网站应用和访问加速
动态网页PHP中引用&的使用注意事项
在PHP中全面阻止SQL注入式攻击
PHP自带可以代替echo调试的unit函数
小结:PHP动态网页程序优化及高效提速问题
php对特殊语句查询结果进行数组排序
实例:用PHP技术解决网站URL格式过长的问题
小结:PHP动态网页程序两个有用的小技巧
动态网页中直接不让访问PHP程序文件
网页实例:详细介绍用PHP来编写网页记数器
菜鸟学习:动态网页PHP基础学习笔记
利用Apache实现禁止图片盗链
PHP编程中常用的三则技巧
PHP制作的网站意见在线反馈表
大型Web需求解决方案 PHP定位突出
PHP实例:精确到每一秒钟的在线人数显示代码
实用:动态网页制作技术PHP的十个应用技巧
常见php页面漏洞分析及相关问题解决
PHP和MYSQL制作动态网站开发经验之谈

PHP 中的 使用 php4 加速 web 传输


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 41 ::
收藏到网摘: n/a

<?
/***************************************
**Title.........:PHP4HTTPCompressionSpeedsuptheWeb
**Version.......:1.10
**Author........:catoc<[email protected]>
**Filename......:gzdoc.php
**Lastchanged..:25/08/2000
**Requirments...:PHP4>=4.0.1
**PHPwasconfiguredwith--with-zlib[=DIR]
**Notes.........:DynamicContentAccelerationcompresses
**thedatatransmissiondataonthefly
**codebysunjinhu(catoc)<[email protected]>
**Mostnewerbrowserssince1998/1999have
**beenequippedtosupporttheHTTP1.1
**standardknownas"content-encoding."
**Essentiallythebrowserindicatestothe
**serverthatitcanaccept"contentencoding"
**andiftheserveriscapableitwillthen
**compressthedataandtransmitit.The
**browserdecompressesitandthenrenders
**thepage.
**Useage........:
**Nospacebeforethebeginningofthefirst'<?'tag.
**------------Startoffile----------
**|<?
**|include('gzdoc.php');
**|print"Startoutput!!";
**|?>
**|<HTML>
**|...thepage...
**|</HTML>
**|<?
**|gzdocout();
**|?>
**-------------Endoffile-----------
***************************************/
ob_start();
ob_implicit_flush(0);
functionGetHeader(){
$headers=getallheaders();
while(list($header,$value)=each($headers)){
$Message.="$header:$value<br>n";
}
return$Message;
}
functionCheckCanGzip(){
global$HTTP_ACCEPT_ENCODING,$PHP_SELF,$Wget,$REMOTE_ADDR,$S_UserName;
if(connection_timeout()||connection_aborted()){
return0;
}
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-dH:i:s")."n";
$Error_Msg.="Remote-Address:".$REMOTE_ADDR."n";
//mail('[email protected]',"Userhavex-gzipoutputinfile$PHP_SELF!!!",$Error_Msg);
}else{
$ENCODING="gzip";
}
return$ENCODING;
}else{
return0;
}
}
functionGzDocOut(){
global$PHP_SELF,$CatocGz,$REMOTE_ADDR,$S_UserName;
$ENCODING=CheckCanGzip();
if($ENCODING){
print"n<!--Usecompress$ENCODING-->n";
$Contents=ob_get_contents();
ob_end_clean();
if($CatocGz=='Y'){
print"Notcompresslenth:".strlen($Contents)."<BR>";
print"Compressedlenth:".strlen(gzcompress($Contents))."<BR>";
exit;
}else{
header("Content-Encoding:$ENCODING");
}
printpack('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;
printpack('V',$Crc);
printpack('V',$Size);
exit;
}else{
ob_end_flush();
$Error_Msg=str_replace('<br>','',GetHeader());
$Error_Msg.="Time:".date("Y-m-dH:i:s")."n";
$Error_Msg.="Remote-Address:".$REMOTE_ADDR."n";
//mail('[email protected]',"Usercannotusegzipoutputinfile$PHP_SELF!!!",$Error_Msg);
exit;
}
}
?>