|
|
|
<?
/********************************************************************
** Title.........: PHP4 HTTP Compression Speeds up the Web
** Version.......: 1.11
** Author........: catoc <catoc@163.net>
** Filename......: gzdoc.php
** Last changed..: 14/02/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.
** PHP 4.0.4 supports built-in HTTP compression.
** Version 1.11 cleaning code.
** Usage........:
** No space before the beginning of the first '<?' tag.
** ------------Start of file----------
** |<?
** | include('gzdoc.php');
** |?>
** |<HTML>
** |... the page ...
** |</HTML>
** |<?
** | gzdocout();
** |?>
** -------------End of file-----------
*******************************************************************/
ob_start();
ob_implicit_flush(0);
function GzDocOut(){
global $HTTP_ACCEPT_ENCODING, $DEBUG;
$DEBUG = ($DEBUG) ? $DEBUG : 1;
if(preg_match('/(x-gzip|gzip)/', $HTTP_ACCEPT_ENCODING, $EncodeArr)){
$ENCODING = $EncodeArr[1];
$Contents = ob_get_contents();
ob_end_clean();
header("Content-Encoding: $ENCODING");
$Contents .= ($DEBUG) ? "\n<!-- Use compress $ENCODING -->" : '';
if($DEBUG == 2){
$Contents .= "\n<!-- Not compress length: ";
$Contents .= number_format(strlen($Contents) / 1024, 2) . 'K -->';
$Contents .= "\n<!-- Compressed length: ";
$Contents .= number_format(strlen(gzcompress($Contents)) / 1024, 2) . 'K -->';
}
$Size = strlen($Contents);
$Crc = crc32($Contents);
$Contents = gzcompress($Contents);
print pack('c*',0x1f,0x8b,0x08,0x00,0x00,0x00,0x00,0x00);
print substr($Contents, 0, strlen($Contents) - 4);
print pack('V*',$Crc,$Size);
exit;
}else{
print ($DEBUG) ? '<!-- Not compress -->' : '';
ob_end_flush();
exit;
}
}
?> |
|
| WebServerSpy checks which kind of Webserver is running, Apache, Netscape, Fasttrack, IIS, HTTP-Header, HTTP 1.0, GET, spy, WWW Categories : HTTP, Network, Apache, PHP, Web Servers | | | This script shows you the 7th latest php items from the mailing list archive on zend.com Categories : HTML, HTML and PHP, HTTP, PHP | | | Produces browser-safe strings while preserving HTML tags. Categories : Strings, HTTP, PHP, HTML and PHP | | | Pseudo Non Parsed Header. Output to the the browser as the script runs. Categories : PHP, HTTP, HTML and PHP | | | How to let a user download a picture by clicking on it instead of needing to right click and Save-As. Categories : HTTP, PHP, HTML and PHP, Filesystem | | | Browser Detection, Redirection Type, MSIE, MOZILLA, Netscape Navigator, NS, $HTTP_USER_AGENT, HTTP_USER_AGENT Categories : PHP, HTTP, Browsers, HTML and PHP | | | Upload Script, Upload File Script, Input Type="File" Categories : PHP, HTML and PHP, HTTP | | | redirect redirection ip address authentication authenticate addr Categories : Authentication, HTTP, Network, PHP | | | PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use! Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP | | | Message of the Day - Random Message (Needs MySQL!) Categories : Databases, HTML and PHP, PHP, MySQL | | | A simple class with some HTML output functions that would come in handy for consistent page layout etc. Categories : PHP, PHP Classes, HTML and PHP, HTML, Navigation | | | a function that builds an HTML select list from any mysql table. Categories : PHP, MySQL, HTML and PHP | | | Select with current month Categories : PHP, HTML and PHP, Date Time, Arrays | | | Check parameters validity. Paranoia was designed to check the validity of the parameters that a php page will receive after a form submission. It can be used to check the variables sent by POST or GET Categories : Algorithms, HTML and PHP, PHP, Variables | | | Constantly refresh your PHP/HTML page data. Categories : PHP, HTML and PHP, Sybase | |
| | | | Ingmar Mohring wrote : 526
hi
since php4.0.4pl1 you can use
ob_start("ob_gzhandler");
but use it carefully, i ran it on a site with about 1000 connections at an avarage.
and the serverload was up to 35 in notime, so i took it back off
| | | | cat oc wrote :533
The ob_gzhandler has a huge memory leak in php 4.0.4 && php 4.0.4pl1 and it is already fixed in CVS. IF you do want to use the handler please update using the last CVS version.
| |
|
|
|