Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 10-13-2007, 06:13 PM how to use gzip?
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
How could i have all out putted code and that gzipped?
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
 
Register now for full access!
Old 10-13-2007, 07:45 PM Re: how to use gzip?
Moxxnixx's Avatar
King Spam Talker

Posts: 1,174
Name: Lance
Location: Virginia Beach
Trades: 0
You can use this...
PHP Code:
<?php 
ob_start
("ob_gzhandler"); 

<!-- 
your content --> 

?>
__________________
Get your facts first, and then you can distort them as much as you please. - Mark Twain

Please login or register to view this content. Registration is FREE
---

Please login or register to view this content. Registration is FREE

All My Sites Are Proudly Hosted @
Please login or register to view this content. Registration is FREE

Moxxnixx is offline
Reply With Quote
View Public Profile Visit Moxxnixx's homepage!
 
Old 10-13-2007, 10:30 PM Re: how to use gzip?
Experienced Talker

Posts: 44
Name: Kuldeep Sahi
Trades: 0
Call the function ob_start("ob_gzhandler"); at the top of your script as suggested by Moxxnixx

Also remember to call the function ob_flush(); at end

PHP Code:
<?php 
ob_start
("ob_gzhandler"); 
?>

<!-- your content --> 

<?php
ob_flush
();
?>
__________________

Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE
Kuldeep2195 is offline
Reply With Quote
View Public Profile Visit Kuldeep2195's homepage!
 
Old 10-14-2007, 07:06 AM Re: how to use gzip?
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
and that is it?

So all i would have to do is have ob_start("ob_gzhandler") and ob_flush() at the begining and end of my pages and the output will be compressed (if the browser accepts gzip compression)

Correct?
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 10-14-2007, 07:59 AM Re: how to use gzip?
Moxxnixx's Avatar
King Spam Talker

Posts: 1,174
Name: Lance
Location: Virginia Beach
Trades: 0
Normally, that's it...assuming your host has it enabled in PHP.
__________________
Get your facts first, and then you can distort them as much as you please. - Mark Twain

Please login or register to view this content. Registration is FREE
---

Please login or register to view this content. Registration is FREE

All My Sites Are Proudly Hosted @
Please login or register to view this content. Registration is FREE

Moxxnixx is offline
Reply With Quote
View Public Profile Visit Moxxnixx's homepage!
 
Old 10-14-2007, 08:48 AM Re: how to use gzip?
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
ok, i just saw something on vb admin whats mod_gzip and mod_deflate?
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 10-14-2007, 08:49 AM Re: how to use gzip?
Experienced Talker

Posts: 44
Name: Kuldeep Sahi
Trades: 0
As an Acid test, check out the results of your page on
http://www.gidnetwork.com/tools/gzip-test.php
and see the gzip improvement
__________________

Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE
Kuldeep2195 is offline
Reply With Quote
View Public Profile Visit Kuldeep2195's homepage!
 
Old 10-14-2007, 09:01 AM Re: how to use gzip?
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
i just found this which is suposed to be a better way to do it.

PHP Code:
<?
// -------------------------------------------------------------------------------------
$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 te be before any output from your site!
// If output exists uncompressed HTML will be delivered!
ob_start("obOutputHandler");
// -------------------------------------------------------------------------------------
?>

basically im looking to add this so my CMS so i can have a option to use gzip compression or not. like all gd cms and forums...

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 10-14-2007, 09:18 AM Re: how to use gzip?
Moxxnixx's Avatar
King Spam Talker

Posts: 1,174
Name: Lance
Location: Virginia Beach
Trades: 0
Dan, I don't see that as being better. It just provides an unnecessary step to check if gzip is enabled.
If any host is smart, they would have it enabled to save bandwidth for them and their customers.
But, that's your choice. I don't see it hurting anything.
__________________
Get your facts first, and then you can distort them as much as you please. - Mark Twain

Please login or register to view this content. Registration is FREE
---

Please login or register to view this content. Registration is FREE

All My Sites Are Proudly Hosted @
Please login or register to view this content. Registration is FREE

Moxxnixx is offline
Reply With Quote
View Public Profile Visit Moxxnixx's homepage!
 
Old 10-14-2007, 09:32 AM Re: how to use gzip?
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Ok also all the stuff i seen just says to put the first part and dont say to put ob_flush() at the end is it necessary?

And what would be the best way to control this throw database? simple if?
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 10-17-2007, 12:42 PM Re: how to use gzip?
VirusDoctor's Avatar
Skilled Talker

Posts: 53
Name: Shaun
Trades: 0
I have a much better way of enabling it and best of all it works throughout your site from one location.

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>
VirusDoctor is offline
Reply With Quote
View Public Profile
 
Old 10-17-2007, 12:50 PM Re: how to use gzip?
Average Talker

Posts: 17
Name: Nilesh Govindarjan
Trades: 0
But then what is

gzcompress()

and

gzdecompress()

??
nilesh.3892 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to how to use gzip?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 2.31101 seconds with 12 queries