Question

I have been searching for a method to display content in a browser while a php script executes a fairly long while loop... using ob_start(), flush(), ob_flush() and ob_end_flush(). It failed.

While researching on php.net I came across a user post that read:

"As of August 2012, all browsers seem to show an all-or-nothing approach to buffering. In other words, while php is operating, no content can be shown."

The post goes on to say that all others posts are irrelevant. If this is true why has PHP.net displayed the necessary functions as deprecated? And if it isn't can some please me how to correctly implement output buffering for the simple script:

function simpleFunction() {
    for ($i = 0; $i < 10000; $i++) {
        $data = $externalJsondata;
        if($data == "True")
        {
        echo ("Output1");
        }
        else{
        echo ("Output2");           
        };
    };   
}

simpleFunction(); 
Was it helpful?

Solution

Answer/Hack provided by: Joe Watkins

function simpleFunction() {
if (!defined('STDOUT'))define('STDOUT', fopen("php://stdout", "w"));
    for ($i = 0; $i < 10000; $i++) {
        $data = $externalJsondata;
        if($data == "True")
        {
        echo ("Output1");
        flush(STDOUT);
        }
        else{
        echo ("Output2");
        flush(STDOUT);        
        };
    };   
}

simpleFunction(); 

Thanks ;)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top