real time Output from php to Browser

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mei
Forum Newbie
Posts: 3
Joined: Mon Jan 13, 2003 3:39 am
Location: Latvia

real time Output from php to Browser

Post by mei »

I need real time otput from php to Browser....

For example: first i print on Screen HTML content... then i need register transaction and output on Screen registration-status....

But that don't works.... first register transaction and then pript on Screen HTML content and registration-status in one time....

Soory, if all not understand.... but i speek english very bad....

P.S. maby i need change some configuration in Apache or PHP
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

maybe I missed the point. Do you want to asure that partial results of your script are sent to the browser before the script's execution continues?
If so, flush() is your best chance.
http://www.php.net/manual/en/function.flush.php
mei
Forum Newbie
Posts: 3
Joined: Mon Jan 13, 2003 3:39 am
Location: Latvia

Post by mei »

Flush() don't work exactly.... how i understand in manual.... Flush don't works with browsers output....

example:

echo "first output\n";
flush();
sleep(10);
esho "second output\n";

line "first output" show on browser after 10 sec. with "second output";
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

nope, all the manual says is: maybe it works, maybe not, depending on your webserver's and the client's configuration. It's still your best chance and worth a try ;)
e.g. my mozilla browser displays the first string long before sleep(10) is finished, while internet explorer refuses to display anything until the script is done :-S
But with

Code: Select all

<html><body><pre><?php
echo "first output\n";
flush();
sleep(10);
echo "second output\n"; 
?></pre></body></html>
both browsers handle the partial data as expected :D
mei
Forum Newbie
Posts: 3
Joined: Mon Jan 13, 2003 3:39 am
Location: Latvia

Post by mei »

my browsers:
Mozilla/5.0- Don't work
IE 5.5 - Don't work
Netscape Comunicator 4.7 - Don't work

Maby need something change in webserver configuration.... but i don't know- what.... :(
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

may also be that your script outputs something that browsers do not render immediately. Part of a table that is not fixed-size e.g. or parts of a <div> that has a relative position but no width-property or ... or ...
Try to encapsulate your output in a <p>...</p>-Block with no further styles before calling flush();
Post Reply