Manual of PHP

 
 
 

Web map

 
rim   rim
arrowReady frontarrow of Codes PHParrow to Compress page PHP

 

To compress page PHP To print E-mail
To lighten the time of load of our pages generated with PHP, we can send them to the navigator compressed with GZip

To lighten the time of load of our pages generated with PHP, we can send them to the navigator compressed with GZip using the functions of control of exit, for it, we will call to the predefined function ob_gzhandler how dealer of the function ob_start, we see an example:

<?
ob_start ("ob_gzhandler");

//Content of the page, it can contain
//so much HTML how PHP

ob_end_flush ();
?>


To bear in mind that the whole content must be in the place indicated therefore the first characters of the document must be <? and two last ones?> and it is not necessary to add anything except where it is indicated, if we do not go carefully we will receive an error similar to the following one:

Warning: Cannot add header information...

Another more finished form still of compression, it consists of applying the same function, but eliminating in turn the spaces and jumps of line of the source of the document, what will not have any visual effect but it will diminish the discharge time, let's see how to do it:

<?
ob_start ();

//Content of the page, it can contain
//so much HTML how PHP

$cntACmp =ob_get_contents ();
ob_end_clean ();
$cntACmp=str_replace ("\n", '', $cntACmp);
$cntACmp=ereg_replace ('[[:space:]] +', '', $cntACmp);
ob_start ("ob_gzhandler");
I begin $cntACmp;
ob_end_flush ();
?>


This method works just as the alone previous one that, before compressing, eliminates the jumps of line and spaces innescesarios, but we must bear in mind the same precautions or it will not work.

I have developed this compression method for ProgramacionWeb, as you will be able comprovar on having seen the code source of the same page, the whole code appears without line jumps not tabulated by a simple compression question.

Eloi of St Martin Lagranje
http://www.programacionweb.net/articulos/articulo/?num=162

 

 
Front
Chapters of the Manual of PHP
Introduction to PHP
Variables
My First Script PHP
Operators in PHP
Structures of Control
Functions in PHP
Code inclusion
Counterfoils (array)
Chains of Characters
Classes
Dates
Entry and Exit
Operations with Files
The language SQL and PHP
Connection with MySQL
Meetings
Forms with PHP
To practise in line
List of practices in line
FAQ
Frequent questions
Codes PHP
List of Codes PHP
Forums
Forums PHP
Other Manuals
Manuals of other languages
 
   
 
 
MySpaceScripts.info - Sitemap - Contact us - Sitemap - Contact us - Sitemap - Contact us

Panasonic , Replica Horloges , DMC Poland , caza polonia , Links patrocinados no Google , Mehrgenerationenhaus , Mortgage