Click to See Complete Forum and Search --> : Showing page 'by parts'


Shandrio
February 17th, 2005, 11:14 AM
Hi Gurus!

I have this very big doubt... I have a PHP script I've made that generates an HTML page "slowly" because I use sockets in the script, which take time to connect and transfer, I have to wait quite much until my whole page is generated until I can finally see it. Is there a way to see it "by parts" as it's beeing generate and not only the final entire page at once?

Here's a pseudocode to show what I mean, in case it's not well understood:


HTML head tags
other HTML stuff

do

PHP script that uses time-consuming sockets
PHP script that shows some output

loop

HTML tail tags


Well, simply what I want is to SEE the output of the code marked in red, every time it executes...... But how?

Thanks in advanced!

khp
February 17th, 2005, 09:18 PM
The reason you are not seeing the page as it's beeing generated is most likely that PHP or your web server is preforming some output buffering.

In PHP output buffering should be off by default, so unless someone enable it, it should not be a problem.
If you are lucky it might be enough to call flush() after the output you want to see is printed.
You can read about PHP's output control functions here.
http://www.php.net/manual/en/ref.outcontrol.php
Of course if someone has explicitly enabled output buffering, turning it off might break the script.
It might also be your webserver doing the buffering, but ofcourse you have to tell us what web server you are using before I can even begin to think about that.

Finally it might also be that your page employs some clientside scripts which prevents the page beeing displayed before the entire page is loaded.

Shandrio
February 18th, 2005, 12:52 AM
Hi, thanks a lot for your help khp! At http://www.php.net/manual/en/ref.outcontrol.php I found some very interesting things about buffering that I didn't know.

As a solution to my problem, the function ob_implicit_flush() simply did magic! It produces EXACTLY what I was expecting PHP to do. Every time I echo a simple line of text, I can immediately see it. The documentation sais that "turning this option on has serious performance implications " but since I'm not in a production enviroment here (because I'm at home :)) it'll do just fine!

Just in case you were curious, I'm running an apache server @ WinXP.

Yours,
Shandrio