G-zip And Mobile Phones
Started on the old forum in September 2008 · view the original in the archive · old links redirect here
TL;DR · summary of 12 replies
- Guest asked about using gzip compression for PHP pages, specifically regarding compatibility with mobile phones.
- monk77 provided details on how to enable mod_deflate module in Apache servers for gzip compression.
- Anshul suggested using ob_gzhandler() function along with the zlib extension for compressing output buffers.
- bijaybd tested gzip functionality and found it works but noted issues with some Nokia models.
Written automatically from the replies by a language model on our own server. It can be wrong; the posts below are the source.
QUOTE (amylee @ Sep 7 2008, 07:07 PM) <{POST_SNAPBACK}>
just enable the mod_deflate module within apache and the difference is minimal with small sites
minimal? lol
I test it with a forum page on lavaliar xhtml.
without gzip: 12 kb = 100 % with gzip compressed: 3kb = 25 %
This is a very great difference. In GPRS-mode your users can save much money with gzip on.
Here a hint to enbable gzip on your servers:
In Apace2 mod_deflate should be installed by default.
Activate it in your server-terminal:
a2enmod deflate
Restart apache:
/etc/init.d/apache2 force-reload
add the following lines to the bottom of your .htaccess:
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/x-httpd-php
The javascript lines are optional.
After that, you can test the gzip compression here: gzip test
u can also do it by using
ob_start("ob_gzhandler");
function to gzip output buffer. ob_gzhandler() requires the zlib extension.You cannot use both ob_gzhandler() and zlib.output_compression. Also note that using zlib.output_compression is preferred over ob_gzhandler().
here is an another method of doing gzip compressions of your web pages
<?
// -------------------------------------------------------------------------------------
$EnableGZipEncoding = true;
// -------------------------------------------------------------------------------------
// Helper function to detect if GZip is supported by client!
// If not supported the tricks are pointless
function acceptsGZip(){
$accept = str_replace(" ","",
strtolower($_SERVER['HTTP_ACCEPT_ENCODING'])
);
$accept = explode(",",$accept);
return in_array("gzip",$accept);
}
// -------------------------------------------------------------------------------------
function playWithHtml($OutputHtml){
// This will mess up HTML code like my site has done!
// View the source to understand! All ENTERs are removed.
// If your site has PREformated code this will break it!
// Use regexp to find it and save it and place it back ...
// or just uncomment the next line to keep enters
// return $OutputHtml;
return preg_replace("/\s+/"," ",$OutputHtml);
}
// -------------------------------------------------------------------------------------
function obOutputHandler($OutputHtml){
global $EnableGZipEncoding;
//-- Play with HTML before output
$OutputHtml = playWithHtml($OutputHtml);
//-- If GZIP not supported compression is pointless.
// If headers were sent we can not signal GZIP encoding as
// we will mess it all up so better drop it here!
// If you disable GZip encoding to use plain output buffering we stop here too!
if(!acceptsGZip() || headers_sent() || !$EnableGZipEncoding) return $OutputHtml;
//-- We signal GZIP compression and dump encoded data
header("Content-Encoding: gzip");
return gzencode($OutputHtml);
}
// This code has to be before any output from your site!
// If output exists uncompressed HTML will be delivered!
ob_start("obOutputHandler");
// -------------------------------------------------------------------------------------
?>
i tried to test my website with - http://www.gidnetwork.com/tools/gzip-test.php
here is the result
Web page compressed? Yes Compression type? gzip Size, Markup (bytes) 4,822 Size, Compressed (bytes) 902 Compression % 81.3
but does it really works i am confused. does it really works with the mobile phones ?
Well Nice reply Anshul my dear .lol., are you sure it will work with all Mobile cell phone ?? Nokia has problem with Gzip even they support Gizp, I tested some Gzip Function on Nokia 6030, Nokia 6070 and more one, it show blank page or some time keep reloading if enable Gzip function, Am talking about XHTML version not WML:D Sutta kam mara kar oye, khatam hojayga hahahahaha......, I got a function for Gzip its realy nice but I fixed it for some sets wich not support GZIP. so even if you test them than they show GZIP n Deflate. I want for all sets support, is there any possiblity .think.
Add the following into your .htaccess file:
<IfModule mod_gzip.c> mod_gzip_on Yes mod_gzip_static_suffix .gz AddEncoding gzip .gz # Save temporary work files [Yes, No] mod_gzip_keep_workfiles No mod_gzip_maximum_file_size 500000 mod_gzip_maximum_inmem_size 60000 mod_gzip_handle_methods GET POST ############### ### filters ### ############### mod_gzip_item_exclude reqheader "User-agent: Mozilla/4.0[678]" # HTML, CGI scripts, PHP mod_gzip_item_include file \.html$ mod_gzip_item_include file \.php$ mod_gzip_item_include file \.pl$ mod_gzip_item_include mime ^text/html$ mod_gzip_item_include mime ^text/plain$ mod_gzip_item_include mime ^httpd/unix-directory$DO NOT DO JavaScript & CSS (due to Netscape4 bugs)
mod_gzip_item_exclude file .js$ mod_gzip_item_exclude file .css$ mod_gzip_item_exclude mime ^image/
mod_gzip_dechunk Yes mod_gzip_add_header_count Yes mod_gzip_send_vary On </IfModule>
by VirusDoctor(webmaster-talk.com)
yeah it doesnt seem to work so great with All mobiles Due to slow signals it can cause problems like constant refreshing
I've got some complaints from users with old mobile phones about that issue (constant refreshing) in the past... Unaware of it, I was already using Gzip at that time.
Can Gzip be the major problem? Or it simple happens in heavy pages with lot's of CSS?
PS: I had to register here again, as I could not login with my old username. Bah!
I use gzip for xhtml sites not for wml because possible problems with some old phones.
Advertise your mobile site for FREE with AdTwirl
yeah I think it because of the slow signal...... when i use my laptop with mobile usb in a 2g zone it does the same thing..... page refreshes over and over.