WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : HTTP gzip compression
Categories : PHP, PHP Classes, Compression, Zlib Click here to Update Your Picture
leaping langoor
Date : Aug 27th 2004
Grade : 2 of 5 (graded 2 times)
Viewed : 9669
File : No file for this code example.
Images : No Images for this code example.
Search : More code by leaping langoor
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

OK. SO this is a simple program... more or les a set of few functions in the form of a class. This is meant gzip compression of the Output so that things are made smaller and faster. This is followed by an example at the bottom. Hope this helps you. One more point, this class is meant usually for large sites!, It wont make much diffrence for smaller ones.

IMPORTANT: READ THE COMMENTS CAREFULLY.




PHP4 HTTP Compression
Class Gzip

Author.......: leapinglangoor [ leapinglangoor@yahoo.co.in ]
Version......: 1.20
Filename.....: gzdoc.php
Updated......: 18/10/2000
Requirments..: PHP4 >= 4.0.1
PHP was configured with --with-zlib[=DIR]

Notes........: Dynamic Content Acceleration compresses
the data transmission data on the fly
code by sun jin hu (catoc) <catoc@163.net>
Most newer browsers since 1998/1999 have
been equipped to support the HTTP 1.1
standard known as "content-encoding."
Essentially the browser indicates to the
server that it can accept "content encoding"
and if the server is capable it will then
compress the data and transmit it. The
browser decompresses it and then renders
the page. This version does not require
GLOBALS to be ON. In case you encounter any
errors, please notify me.


func Gzip
Constructor
Initialise the Gzip output.


compress.php:
<?php

class Gzip
{

function
Gzip()
{
   
ob_start();
   
ob_implicit_flush( 0 );
}

/*
** func CheckCanGzip
**
** Used inside the class( in GzDocOut )
** Checks if Gzip is possible
*/
function CheckCanGzip()
{
    if(
headers_sent() || connection_timeout() || connection_aborted() )
        {
            return
0;
        }

    if(
strpos( $HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'x-gzip' ) !== false ) return "x-gzip";
    if(
strpos( $HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip' ) !== false ) return "gzip";

    return
0;
}

/*
** func GzDocOut
**
** Main function. Outputs the Gzip compilant contents.
**
** @Param $level = compression level 0-9, 0=none, 9=max
*/
function GzDocOut( $level = 3, $debug = 0)
{
   
$ENCODING = CheckCanGzip();
    if (
$ENCODING )
    {
        print
"\n<!-- Use compress $ENCODING -->\n";
       
$Contents = ob_get_contents();
       
ob_end_clean();
        if (
$debug )
        {
           
$s = "<p>Not compress length: ".strlen( $Contents );
           
$s .= "<br>Compressed length: ".strlen( gzcompress( $Contents,$level ) );
           
$Contents .= $s;
        }
       
header( "Content-Encoding: $ENCODING" );
        print
"\x1f\x8b\x08\x00\x00\x00\x00\x00";
       
$Size = strlen( $Contents );
       
$Crc = crc32( $Contents );
       
$Contents = gzcompress( $Contents,$level );
       
$Contents = substr( $Contents, 0, strlen( $Contents ) - 4 );
        print(
$Contents );
        print(
pack( 'V', $Crc ) );
        print(
pack( 'V', $Size ) );
        exit;
    }
    else
    {
           
ob_end_flush();
            exit;
    }
// IF( $ENCODING );
} //function GzDocOut

} // Class Gzip
?>


As always, here is my example... Read carefully the comments.


Example.php
<?php
   
// Initialise the class and constructor.
   
include('compress.php');
   
$gz = new Gzip();

   
/*
        The page
        Anything you want to put in here.
        Including HTML stuff
    */

    // Set the level of compression.
    // 0 - No compression;
    // 9 - Max compresson;
   
$level = 3;

   
// Set debug mode
    // 1 - True; 0 - False
   
$debug = 0;

   
$gz->gzdocout( $level, $debug );
?>



3 lines of Code to extract Tar, Zip, Gzip etc..
Categories : PHP, Filesystem, PHP Classes, Compression
PHP Zip Utility
Categories : PHP, PHP Classes, Compression
Remote Archive (Zip, Tar, Gzip) downloader with FTP and local extration support
Categories : PHP, FTP, Filesystem, PHP Classes, Compression
Reduce PHP/HTML File Sizes
Categories : PHP, Compression, HTML and PHP, Zlib
ADODB Database Wrapper Abstraction Library for PHP: MySQL, MSSQL, Oracle, Interbase,ODBC, Microsoft Access and FoxPro.
Categories : PHP Classes, Databases, PHP, General SQL, ODBC
SPL and ITERATOR : examples
Categories : PHP, Object Oriented, PHP Classes, Sessions
Automatic generation of HTML code for a table. OO interface. Can define colspan, rowspan, table style, cell style, and data style. Simple, but effective.
Categories : PHP, PHP Classes, HTML, HTML and PHP
Simple class to build tables with style sheets
Categories : HTML and PHP, PHP Classes, PHP
A class for sending email; it has support for To:, Cc:, Bcc: and Reply-To: headers. It requires that you have sendmail installed.
Categories : Email, PHP Classes, PHP
PHP MIME Decoder. This class decodes Mime Encoded email message. Attachments are stored in a director. Works with Multipart/alternative, multipart/mixed etc. see http://p3mail.com for example.
Categories : PHP, PHP Classes, Email
XML To Array
Categories : PHP, PHP Classes, XML, Arrays
imageMarker v 3.00 with new advanced features
Categories : PHP, PHP Classes, Graphics, GD image library
AutoRSS
Categories : PHP, Rich Site Summary (RSS), PHP Classes
credit card security code
Categories : PHP, Credit Cards, PHP Classes, Credit Cards
Greatest Common Denominator - A simple class that finds the greatest common denominator for two integers.
Categories : PHP, PHP Classes, Math.