How to allow progressive rendering of page with many PHP functions blocks?


#1

I am trying to suppress buffering of a script with many PHP function calls. On my localhosts–both XAMPP and WAMP–the page is rendered immediately, with status update text echoed at the completion of each PHP function; i.e. the page is rendered top-down, with HTML/CSS elements rendered as they are read, as well as the PHP function blocks.

The same script on DreamHost waits until it is finished processing it in its entirety before displaying any of the HTML & text status that are indicated to be echoed.

PhpInfo.php reveals identical set-ups for both my localhosts and for Dreamhost in every area that might affect this (output buffering, gzip, etc.)

I have tried placing this code at the top of the script to see if it will allow the page to render progressively:

@apache_setenv(‘no-gzip’, 1);
@ini_set(‘implicit_flush’, 1);
@ini_set(‘output_buffering’, ‘Off’);
ob_implicit_flush(1);

My localhosts still process the page with progressive rendering as before. On Dreamhost, however, I receive a blank page with nothing in its source; the directives would seem to stop the script entirely.

How may I allow the script to render/display progressively as on my localhosts? I don’t understand why the behavior is so different for them (specifically, XAMPP and WAMP, which both render the page from the script progressively) and Dreamhost (which defers display of the page until everything is fully processed).

(Please ask for specifics regarding PHP INI settings, etc., as there may be some I have not investigated.)


#2

What’s in your phprc? I’d think putting this in would do it:


#3

Setting output_buffering to Off makes no difference. I’m on a shared server. If you are as well, try running this code; if it displays each text message in sequence, with the stated number of seconds as the delay between text messages, then I’ll be very curious what other settings you’re using, as I cannot get this code to render the text until the entire script is finished processing (i.e., it only flushes the buffer after the entire script is processed):

[code]<?php
header( ‘Content-type: text/html; charset=utf-8’ );

while (@ob_end_flush());

function sendMsg($msg) {
echo $msg;
flush();
}

function sleep_test($sleep_time) {

$x = "Beginning process:<br>";
sendMsg($x);
$y = "Waiting $sleep_time seconds ...<br>";
sendMsg($y);
sleep($sleep_time);
$z = "Done.<br><br>";
sendMsg($z);

}

sleep_test(1);
sleep_test(2);
sleep_test(3);
?>
[/code]


#4

I ran that on a VPS with PHP 5.5:

[quote]Beginning process:
Waiting 1 seconds …
Done.

Beginning process:
Waiting 2 seconds …
Done.

Beginning process:
Waiting 3 seconds …
Done.
[/quote]

Mind it shows it all at once, fully rendered. It’s not progressive at all.

And when I ran it on shared with PHP 5.6 I got the same thing.