PHP: Funkce pro ��zen� v�stupu - Manual
PHP  
downloads | documentation | faq | getting help | mailing lists | | php.net sites | links | my php.net 
search for in the  
<ovrimos_rollbackflush>
view the version of this page
Last updated: Thu, 15 Jul 2004

LXXXI. Funkce pro ��zen� v�stupu

�vod

Funkce pro ��zen� v�stupu v�m umo��uj� ovl�dat, kdy se ode�le v�stup skriptu. To m��e b�t u�ite�n� v n�kolika r�zn�ch situac�ch, zvl�t� pokud pot�ebujete poslat browseru hlavi�ky pot�, co v� skript za�al odes�lat data. Output Control funkce neovliv�uj� hlavi�ky odeslan� pomoc� funkc� header() nebo setcookie(), pouze funkce jako echo() a data mezi bloky PHP k�du.

Po�adavky

Tyto funkce jsou k dispozici jako sou��st standardn�ho modulu, kter� je v�dy dostupn�.

Instalace

K pou��v�n� t�chto funkc� nen� t�eba ��dn� instalace, jsou sou��st� j�dra PHP.

Konfigurace b�hu

Chov�n� t�chto funkc� je ovlivn�no nastaven�m parametr� v php.ini.

Tabulka 1. Konfigura�n� volby ��zen� v�stupu

N�zevV�choz� hodnotaLze zm�nit
output_buffering"0"PHP_INI_PERDIR|PHP_INI_SYSTEM
output_handlerNULLPHP_INI_PERDIR|PHP_INI_SYSTEM
implicit_flush"0"PHP_INI_PERDIR|PHP_INI_SYSTEM
Pro bli��� podrobnosti a definici PHP_INI_* konstant viz ini_set().

Zde je stru�n� vysv�tlen� konfigura�n�ch direktiv.

output_buffering boolean/integer

��zen� v�stupu m��ete povolit pro v�echny soubory nastaven�m t�to direktivy na 'On'. Pokud chcete omezit velikost bufferu na ur�itou hodnotu, m��ete jako hodnotu t�to direktivy m�sto 'On' pou��t maxim�ln� po�et byt� (nap�. output_buffering=4096).

output_handler string

Cel� v�stup va�ich skript� m��ete p�esm�rovat do funkce. Nap��klad pokud nastav�te output_handler na mb_output_handler(), k�dov�n� znak� bude transparentn� p�ek�dov�no do zadan�ho k�dov�n�. Nastaven� jak�koliv funkce automaticky zapne ��zen� v�stupu.

Pozn�mka: Nem��ete pou��vat najednou mb_output_handler() s ob_inconv_handler() a nem��ete pou��vat najednou ob_gzhandler() a zlib.output_compression.

implicit_flush boolean

Ve v�choz� nastaven� je FALSE. Zm�na na TRUE ozn�m� PHP, aby ozn�milo v�stupn� vrstv�, aby se automaticky vypr�zdnila po ka�d�m vypsan�m bloku. Je to ekvivalentn� vol�n� PHP funkce flush() po ka�d�m zavol�n� funkce print() nebo echo() a po ka�d�m HTML bloku.

Kdy� se PHP pou��v� v prost�ed� webu, zapnut� t�to volby m� z�va�n� v�konnostn� d�sledky a obecn� se doporu�uje ho pou��vat pouze pro lad�n�. Tato hodnota m� v�choz� nastaven� TRUE pokud pracujete pod CLI SAPI.

Viz tak� ob_implicit_flush().

Typy prost�edk�

Toto roz���en� nem� definov�n ��dn� typ prost�edku (resource).

P�eddefinovan� konstanty

Toto roz���en� nem� definov�ny ��dn� konstanty.

P��klady

P��klad 1. Uk�zka ��zen� v�stupu

<?php

ob_start
();
echo
"Ahoj\n";

setcookie ("cookiename", "cookiedata");

ob_end_flush();

?>

Ve v��e uveden� uk�zce se v�stup z echo() ulo�� ve v�stupn�m bufferu a� do vol�n� ob_end_flush(). Mezit�m vol�n� setcookie() �sp�n� ulo�ilo cookie bez vyvol�n� chyby. (Norm�ln� nem��ete odeslat do browseru hlavi�ky pot�, co u� byla odesl�na data.)

Pozn�mka: P�i p�echodu z PHP 4.1 (a 4.2) na 4.3 mus�te kv�li chyb� ve star��ch verz�ch zaru�it, aby v php.ini byla direktiva implict_flush nastavena na OFF, jinak v�stup po zavol�n� funkce ob_start() nebude skryt z v�stupu.

Obsah
flush -- Odeslat v�stupn� buffer
ob_clean --  Clean (erase) the output buffer
ob_end_clean --  Vy�istit (vymazat) v�stupn� buffer a vypnout bufferov�n� v�stupu
ob_end_flush --  Vypr�zdnit (odeslat) v�stupn� buffer a vypnout bufferov�n� v�stupu
ob_flush --  Flush (send) the output buffer
ob_get_clean --  Get current buffer contents and delete current output buffer
ob_get_contents -- Vr�tit obsah v�stupn�ho bufferu
ob_get_flush --  Flush the output buffer, return it as a string and turn off output buffering
ob_get_length -- Vr�tit d�lku v�stupn�ho buffer
ob_get_level --  Return the nesting level of the output buffering mechanism
ob_get_status --  Get status of output buffers
ob_gzhandler --  ob_start callback function to gzip output buffer
ob_implicit_flush -- Vypnout/zapnout implicitn� flush
ob_list_handlers --  List all output handlers in use
ob_start -- Zapnout bufferov�n� v�stupu
output_add_rewrite_var --  Add URL rewriter values
output_reset_rewrite_vars --  Reset URL rewriter values


add a note add a note User Contributed Notes
Funkce pro ��zen� v�stupu
gruik at libertysurf dot fr
10-Jul-2004 12:53
For those who are looking for optimization, try using buffered output.

I noticed that an output function call (i.e echo()) is somehow time expensive. When using buffered output, only one output function call is made and it seems to be much faster.
Try this :

<?php
your_benchmark_start_function
();

for (
$i = 0; $i < 5000; $i++)
   echo
str_repeat ("your string blablabla bla bla", (rand() % 4) + 1)."<br>\n";

echo
your_benchmark_end_function();
?>

And then :

<?php
your_benchmark_start_function
();

ob_start ();
for (
$i = 0; $i < 5000; $i++)
   echo
str_repeat ("your string blablabla bla bla", (rand() % 4) + 1)."<br>\n";

echo
your_benchmark_end_function();
ob_end_flush ();
?>
nobbie @t php d0t net
01-Apr-2004 12:49
There is a problem in MSIE 5.5,6 with regards to Page compression. Users might experience pages not loading completely, or just a blank page.

This articles you are looking for is what you're looking for:
 Microsoft Knowledge Base Article - 312496 (for MSIE 6)
 Microsoft Knowledge Base Article - 313712 (for MSIE 5.5)

It states that you should upgrade to the latest MSIE Service Pack to fix the following problem:

Internet Explorer May Lose the First 2,048 Bytes of Data That Are Sent Back from a Web Server That Uses HTTP Compression
tijmen
09-Jul-2003 11:44
Trying to benchmark your server when using output_buffering ?
Don't forget that the value 4096 in the php.ini will give you complete different loadtimes compares to the value of 1.
In the first case the output will be sent after buffering 4096 and the loadtime timed at the end of the page will contain the loadtime needed to download the complete page in the clientbrowser while the second value will contain the loadtime needed to place the complete page in the buffer. The time needed for sending is not clocked.
This can be very frustrating if you don't see the differance between server and the 1st is using 4096 instead of 1.
Although technically much faster than the second server the second server was providing much better loadtime results.
This result will grow when using large amounts of output.
But this becomes interesting if you want to measure the time needed for the page to be loaded for the client.
philip at thepr()jects dot ()rg
08-Feb-2001 07:17
A few tutorials exist on this subject :

*
*

<ovrimos_rollbackflush>
 Last updated: Thu, 15 Jul 2004
show source | credits | sitemap | contact | advertising | mirror sites 
Copyright © 2001-2004 The PHP Group
All rights reserved.
This unofficial mirror is operated at: /
Last updated: Sun Nov 14 23:09:54 2004 Local time zone must be set--see zic manual page