We have a ubuntu test server that this simple script works fine on where it outputs a number each second to the browser
<?
for ($i=0; $i<3; $i++)
{
echo $i.'<br>';
flush();
sleep(1);
}
However on my local development box (windows environment) I cannot get it to work, it outputs it all after 3 seconds.
I am using the same php version (5.3.13) as well as apache (2.2.22) version on my local box as the test server.
I have mirrored most of the settings in both php.ini as well as the httpd.conf
Here are settings I have set (which are identical to the test server)
output_buffering 0
zlib.output_compression = Off
zlib.output_compression_level = -1
I don’t have mod_gzip installed.
I have even tried doing a wamp install on my box, and it didn’t work with that either.
I can’t imagine it being a client (browser — firefox 13) issue as I use the exact same browser to view the script on the test server and it works fine
I have tried enabling implicit flush, doing ob_flush, etc. No luck.
Anyone have any ideas on how to get this working?
Just keep in mind what @Wrikken said, this is not recommended.
So I was thinking, everything you’re doing seems to be right. I copied your setup and tried. I faced same problem. I executed the script from command line, it worked.
Then I had to do the last test, Wireshark. Following the first couple of packets it was clear that the server is sending everything correctly, so it had to be the browser’s buffer.
So I tried send some data before the loop, well guess what? It worked!
Here you go:
I’m not sure about the application you have in mind, but this is clearly not a good idea, I highly recommend that you look into other options.
Update:
After a lengthy Google search I found this and this
And
So I tried to send the charset first instead of filling the buffer: (and it worked)
So why was it working with the first server but not the second?
Most likely it’s because your first server is sending the charset with the header while the second one isn’t.
In your case, however, I’d make the following changes