ahoura
ahoura

Reputation: 689

how to show results while a php script is still running

so I have tried Show results while script is still executing

but for some reason it doesnt work, so here is what I have so far :

ob_start();
include "../../common.php";

set_time_limit (0);

$start = (string) $_GET['start'];
$end = (string) $_GET['end'];

for($i = $start; strcmp($i, $end); $i = bcadd($i, 1)){

echo $i;
ob_flush();

}

ob_end_flush(); 

UPDATED CODE

*note that this code doesnt work yet!

set_time_limit(0);

$start = $_GET['start'];
$end = $_GET['end'];

for(;$start < $end;$start++){
$content = file_get_contents("[some internal page]");
echo $content;
usleep(10); 
flush();
}

Upvotes: 3

Views: 1270

Answers (3)

DaveRandom
DaveRandom

Reputation: 88697

Try adding a call to flush() after the call to ob_flush(). This will only work if your server is configured to be able to do it, and does not guarantee that the client will handle it sensibly, but it is your best bet.

One sticking point I have come across here is that is you have zlib.output_compression configured you absolutely cannot do this, full stop. The zlib output compression process is started before any of your code is executed and cannot be controlled by your script at run time with ini_set() and the like.

Upvotes: 3

Wige
Wige

Reputation: 3918

After ob_flush(); add flush(); That actually flushes the write buffer and output buffers. ob_flush flushes into the write buffer, flush() then pushes it out to the client. Usually at least.

Upvotes: 1

Brad
Brad

Reputation: 163612

You typically need to call both flush() and ob_flush(). See: http://php.net/manual/en/function.flush.php

Also, you cannot do anything about the browser's buffer on the client side. The browser will buffer data as long or as little as it wants. Some servers may also not support flushing their buffer.

Upvotes: 1

Related Questions