First, Sorry by me english
My question is
How get the size of Gzip compressed file and show in cprs.php script?
To compress my html I use php/gzip this is the method that i use:
In
.htacess
Code:
# my pages are xhtml 1.0 and include XML declaration. to prevent PHP errors with <? ..... ?>
php_value short_open_tag 0
#.....enable compression
php_value zlib.output_compression 1
php_value zlib.output_compression_level 9
# for some reason if i put AddType here (overwriting the Apache config) I don't need include header("Content-Encoding: gzip"); in the scripts
AddType application/x-httpd-php .php .php4
# for now .php and .php files are COMPPRESSED
# next 2 lines Apache process other text extension via cprs.php script
AddHandler cprs .htm .html .css .js .txt .xml .xsl
Action cprs /extra/cprs.php
# END htaccess
cprs.php Code
PHP Code:
<?php
### append at the end of each processed file
$mostrar_pie = 1;
$mensaje="";
$creado=date("m/d/Y H:i:s");
### Get the url and file extension
$archivo = $_SERVER["PATH_TRANSLATED"];
$droot = $_SERVER["DOCUMENT_ROOT"];
$servername = $_SERVER["SERVER_NAME"];
if (!file_exists($archivo)){
$errnu= 1;
header("Location: /error/404.html?error=$errnu");
}else{
# Extension
$ext_array =explode(".",$archivo);
$posicion_final = count($ext_array) - 1 ;
$extension = $ext_array[$posicion_final] ;
# URL
$convertir_slash = str_replace('\\\\','/',$archivo);
$tam = strlen($droot);
$url = str_replace('\\','/',$archivo);
$url2 = substr_replace($url, "http://" . $servername , 0, $tam);
$urlr = substr_replace($url, "" , 0, $tam);
# Start compression
ob_start();
# For each extension type asign a apropiate Content-Type and particular headers
# Also append a personal header Licencia:
# Css require special code to force browser caching (thanks to [url]www.fiftyfoureleven.com[/url])
if (($extension == "html")||($extension == "htm")){
header("Licencia: GcG");
header("Content-Type: text/html; charset=iso-8859-1");
}elseif($extension == "css"){
header("Licencia: GcG");
header("Content-Type: text/css");
header("Cache-Control:must-revalidate");
$offset = 60 * 60;
$ExpStr = "Expires:" .
gmdate("D,d M Y H:i:s",time() + $offset) . " GMT";
header($ExpStr);
}elseif($extension == "js"){
header("Licencia: GcG");
header("Content-Type: text/javascript");
}elseif($extension == "txt"){
header("Licencia: GcG");
header("Content-Type: text/plain; charset=iso-8859-1");
}elseif(($extension == "xml")||($extension == "xsl")){
header("Licencia: GcG");
header("Content-Type: text/xml");
}else{
$nada ="";
}
$rf = @readfile($archivo);
### Append the footer based on file extension
/* *************************************************************************************** */
if ($mostrar_pie == 1) {
$lineap = "----------------------------------------------------------------------------------------------";
if ($extension == "js"){ $mensaje = "\n// $creado - Documento Php/Gzip comprimido - ©2003 G. Gianello - $servername\n\n";}
if (($extension == "html")||($extension == "htm")||($extension == "xml")||($extension == "xsl")) {
$mensaje = "\n\n\n<!-- $creado - Documento Php/Gzip comprimido - ©2003 G. Gianello - $servername -->\n\n";}
if ($extension == "txt"){ $mensaje = "\n$lineap\n$creado - Documento Php/Gzip comprimido - ©2003 G. Gianello - $servername OK\n\n";}
if ($extension == "css"){ $mensaje = "\n/* $creado - Documento Php/Gzip comprimido - ©2003 G. Gianello - $servername */\n\n";}
$archivo_string = str_replace('\\\\','\\',$archivo);
echo $mensaje;
}
ob_end_flush();
}
?>
################################################## ##
OK, I check the method in many ways and WORK Fine in all cases.
In my Remote webserver (Linux + Apache 2 + Php 4.3) and my local intranet (WinXP + Apache 1.3.27 + Php 4.3)
Test 1
======
Online test
Code:
The PhiliWeb Site-Test Gzip = Passed
leknor.com = Passed
www.desilva.biz = Passed
Test 2
======
Using Firefox 1.0.4 and WebDeveloper Plugin and enable/disable php_value zlib.output_compression in .htaccess
For php_value zlib.output_compression 0 (no compression)
Code:
Response Headers - ....
Date: Sat, 19 Nov 2005 20:32:15 GMT
Server: Apache/1.3.27 (Win32) mod_perl/1.27_01-dev
Licencia: GcG
200 OK
************************************************** ****************************
For php_value zlib.output_compression 1 (Compression enable)
Code:
Response Headers - .......
Date: Sat, 19 Nov 2005 20:45:39 GMT
Server: Apache/1.3.27 (Win32) mod_perl/1.27_01-dev mod_gzip/1.3.26.1a
Licencia: GcG
Content-Encoding: gzip --------------------------------------------------------------------------------->>>> Compress
Vary: Accept-Encoding --------------------------------------------------------------------------------->>>> Compress
200 OK
Test 3
======
in this sample use gztest.txt (50000 bytes)
Windows filesystem report 48,8 KB (50.000 bytes)
In the Firefox, right click, page info report 0.37 KB (375 bytes)
Test 4
========
Opera 8 Cache display
opr00TQX.txt --- 374 ----
emprear.com.local
Tests 5
======
Go to Opera Cache folder
Double Click in opr00TQX.txt (374bytes) and notepad show something like this
Code:
‹ ìбJÃ@à=Ðw¸hš¨*¸•q° “[¨$M¨qéù–^]\uÐA¾7ÿßßqíÓí.<Æ×9lSÅÍWE{JS˜Ïå_ìx<?Çãñx<?Çãñx<?Çãñx<?Çãñx<?Çãñx<?Çãñx<?Çãñx<?Çãñx<?Çãñx<?Çãñx<?Çãñx<?Çãñx<?Çãñx<?Çãñx<?Çãñx<?Çãñx<?Çãñx<?Çãñx<?Çãñx<?Çãñx<?Çãñx<?Çãñx<ï{?*ü'?Çãñx<?Çû¾·M}éCSå”yT,5E]¯êõꢪšP¯¯ój®Â2lÆýÛóv/Óêó‰ûq˜ŽiHÏcîßó…ËЖ¡MÝ!öýys»c™–ý¸ïúpW ÿÿâå‚@ ÿÿ ENƒÄ
Now (you need winrar instaled in the system), rename opr00TQX.txt as opr00TQX.txt.rar, double click and now, you can see opr00TQX.txt into the rar file, open and Notepad show the uncompressed version of txt file.
Last, remember my original question
How get the size of Gzip compressed file and show in cprs.php script?
Thanks
Emprear
Buenos Aires