GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 19-Nov-2005, 15:40
emprear emprear is offline
New Member
 
Join Date: Nov 2005
Posts: 1
emprear is on a distinguished road
Thumbs down

Gzip: compressed file size?


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
Attached Files
File Type: txt gztest.txt (48.8 KB, 14 views)
Last edited by LuciWiz : 20-Nov-2005 at 11:25. Reason: Please insert your PhP code between [php] & [/php] tags
 

Recent GIDBlogNARMY by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Airport Log program using 3D linked List : problem reading from file batrsau C Programming Language 11 29-Feb-2008 07:44
Determing size of a binary file Dream86 CPP / C++ Forum 7 01-Jun-2005 10:10
Having a problem Chuckles Computer Hardware Forum 19 13-Sep-2004 12:17
CD burner wont burn!! robertli55 Computer Hardware Forum 1 18-Jun-2004 10:53
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 11:28

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:41.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.