【PHP的优化,缓冲,压缩】教程文章相关的互联网学习教程文章

关于PHP开启zlibgzip压缩配置的方法

zlib.output_compression = Off;zlib.output_compression_level = -1 修改为:zlib.output_compression = Onzlib.output_compression_level = 6其中,zlib.output_compression_level = 6 的数字6是压缩比例 二、打开apache 配置文件httpd.conf,配置装载deflate_module,找到 #LoadModule deflate_module modules/mod_deflate.so 把前面的注释“#”号去掉 三、重启apache,测试下网站是否开启压缩。

php中gzip对文件或字符串解压缩的例子

/*** php自定义gzdecode解压缩gzip文件* edit bbs.it-home.org*/if (!function_exists('gzdecode')) { function gzdecode ($data) { $flags = ord(substr($data, 3, 1)); $headerlen = 10; $extralen = 0; $filenamelen = 0; if ($flags & 4) { $extralen = unpack('v' ,substr($data, 10, 2)); $extralen = $extralen[1]; $headerlen += 2 + $extralen; } if ($flags & 8) // Filename $headerlen = strpos($data, chr(0), $heade...

php中启用gzip页面压缩输出的配置方法

本文介绍下,在php中开启gzip页面压缩输出的方法,供大家学习参考。有关在php中配置gzip压缩的要点: 1、默认php是不开启zlib整站压缩输出的,而是通过对需要压缩输出的页面使用ob_gzhandler函数实现,两者只能二选一,否则会报错。 2、zlib.output_compression默认值为Off,你可以将其设置为On,或者output buffer size(默认为4k) 3、zlib.output_compression_level代表压缩比,默认推荐设置压缩比值为6,可选范围为1-9,-1代表关...

php开启gzip压缩的三种可靠方法

output_buffering = Off 3,php.ini为;output_handler = ob_gzhandlerzlib.output_compression = Off;zlib.output_compression_level = -1 4,apache增加如下:AddOutputFilter DEFLATE html php js css方法2,使用php.ini中的zlib.output_compression 1,关闭apache中的mod_deflate.so 2,php.ini:output_buffering = On 2,php.ini为;output_handler = zlib.output_compression = Offzlib.output_compression_level = 6(等级-1...

在php虚拟主机中启用gzip压缩的方法

define('ABSPATH', dirname(__FILE__).'/');$cache = true;//Gzip压缩开关$cachedir = 'gzip_cache/';//存放gz文件的目录,使用前创建,并赋予可写权限$gzip = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');$deflate = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate');$encoding = $gzip ? 'gzip' : ($deflate ? 'deflate' : 'none');if(!isset($_SERVER['QUERY_STRING'])) exit();$key=array_shift(explode('?', $_SE...

php中开启Zlib(GZIP)压缩优化的方法

zlib.output_compression = Onzlib.output_compression_level = 6完成后可以通过phpinfo()函数检测结果,当zlib.output_compression的Local Value和MasterValue的值同为On时,表示已经生效,这时候访问的PHP页面(包括伪静态页面)已经GZIP压缩了,通过Firebug或在线网页GZIP压缩检测工具检测到压缩的效果。 若需要使用ob_gzhandler(默认),则需关闭zlib.output_compression,把php.ini文件内容更改为:zlib.output_compression = ...

php实现gzip压缩html数据的代码

本文介绍下,用php实现gzip方法压缩html页面的一例代码,有需要的朋友参考下。代码如下:有兴趣的朋友,可以百度下检测gzip压缩效果的工具或网站,看看压缩比率如何!

php判断服务器是否支持Gzip压缩的方法

phpinfo();?>浏览此页面,例如: http://域名及目录/test.php,例如本站即为:http://bbs.it-home.org/test.php 打开该页面之后,CTRL+F查找以下字符串: _SERVER["HTTP_ACCEPT_ENCODING"] 找到后,检查其后是否有gzip参数。 有的话,此表示空间支持Gzip。 如果没有gzip参数,此网站无法使用Gzip压缩,此时请考虑其它方法吧。

php判断网页是否启用gzip压缩的方法

本文介绍下,用php代码判断网页是否启用gzip压缩的方法,有需要的朋友不妨作个参考。采集网页时发现file_get_contents 获得的网页保存到本地为乱码,响应的header 里 Content-Encoding:gzip,但在浏览器里看是正常的。 由此,可以判断网站开启了gzip而file_get_contents 获得的是压缩过的页面,而不是解压过的页面(不知是否要file_get_conttents 请求网页时带上相应的参数,直接获得没有被gzip压缩过的网页?) 之前看到过可以用读...

php打包一组文件为zip压缩包的类

<?php/*** Zip file creation class.* Makes zip files.** @access public*/class zipfile{ /** * Array to store compressed data * * @public array $datasec */ public $datasec = array(); /** * Central directory * * @public array $ctrl_dir */ public $ctrl_dir = array(); /** * End of central directory record * * @public string ...

php压缩多个CSS文件的实现代码

<?php/* * 压缩css文件 * by bbs.it-home.org /*header(Content-type: text/css);ob_start("compress");function compress($buffer) { /* remove comments */ $buffer = preg_replace(!/\*[^*]*\*+([^/][^*]*\*+)*/!, , $buffer); /* remove tabs, spaces, newlines, etc. */ $buffer = str_replace(array("\r\n", "\r", "\n", "\t", , , ), , $buffer); return $buffer;}/* 加载要压缩的css文件 */include(master....

PHP压缩html的函数代码

<?php//函数名: compress_html//参数: $string//返回值: 压缩后的$string//by bbs.it-home.orgfunction compress_html($string) { $string = str_replace("\r\n", , $string); //清除换行符 $string = str_replace("\n", , $string); //清除换行符 $string = str_replace("\t", , $string); //清除制表符 $pattern = array ( "/> *([^ ]*) *</", //去掉注释标记 "/[\s]+/", ...

php在线压缩与解压缩SWF文件的代码(修正版)

//----------------- //文件名 $filename = "test.swf"; //打开文件 $rs = fopen($filename, "r"); //读取文件的数据 $str = fread($rs, filesize($filename)); //设置swf头文件 $head = substr($str, 0, 8); $head[0] = 'F'; //获取swf文件内容 $body = substr($str, 8); //压缩文件内容,使用最高压缩级别9 $body = gzcompress($body, 9); //合并文件头和内容 $str = $head . $body; //关闭读取的文件流 ...

php压缩函数(gzcompressgzuncompress)压缩字符串

<?php//字符串压缩举例$string =“http://bbs.it-home.org is php technical website.This website is personal website.php8848.com has many php and mysql or other IT knowledage articles,so welcome to php8848.com!please enjoy it! it’s our honor if php8848 can help you !”;$compressed = gzcompress($string);echo “Original size: “. strlen($string).”n”;/* printsOriginal size: 800*/echo “Compressed size...

PHP压缩字符串的几种方法

$str = 'Compress meCompress meCompress meCompress meCompress meCompress meCompress meCompress meCompress me';echo "str".strlen($str)."\n";方法1,压缩率最低(gzip压缩算法) 生成结果可以直接写到.gz文件中$data = implode("", file("bigfile.txt"));$gzdata = gzencode($data, 9);$fp = fopen("bigfile.txt.gz", "w");fwrite($fp, $gzdata);fclose($fp);?> 方法2,压缩率居中 –This function compress the given string ...

缓冲 - 相关标签