If I load this script in chrome from my local server on XAMPP:
header("Content-Type:text/plain");
set_time_limit(0);
$max = 40;
for ($i = 0; $i < $max; $i++) {
$response = array( 'server time: ' . date("h:i:s", time()), 'progress' => round($i/$max*100));
echo json_encode($response);
ob_flush();
flush();
sleep(1);
}
ob_clean();
It works as you would expect, every second the page displays a new response. However, when I upload it to my remote server (running the same version of php), it waits until the entire script finishes before it displays the output. On very long scripts, it updates the output every 30-60 seconds or so.
As the title suggests, I've tried using all the different flush functions, but nothing works. There is likely some difference in the php.ini of my local server and my remote server, but I don't know what.
Please help.
---EDIT---
I've been doing some more testing. I've noticed that exactly it only updates every 4096 bytes, which happens to be what my remote server's php ini value for 'output_buffering' is. However, for some reason, if I change output_buffering to '1' or 'off', nothing changes. It still only updates every 4096 bytes.
I'm testing the 2 identical scripts on different servers on the same browser.
flush()
is full of disclaimers of why this may or may not work. It could be something you can't even fix. – Demand