Has anyone found a solution, how to display a message in the browser every second using PHP?
Until now, I’ve always used the following code, which worked fine on my server running IIS 6:
<html>
<body>
<?php
for ($counter = 0; $counter <= 10; $counter++) {
echo "Message after " . $counter . " second(s)<br>";
ob_flush();
flush();
sleep(1);
}
?>
</body>
</html>
I’ve seen several posts that ob_flush
no longer works with the newer IIS versions.
I use IIS on Windows 10.
In some posts I read to add responseBufferLimit="0"
into the section PHP_via_FastCGI
of the file C:WindowsSystem32inetsrvconfigapplicationHost.config
.
But in this file I’ve only the following section about fastCgi
so I’ve no idea how to add responseBufferLimit="0"
into this section:
<fastCgi>
<application fullPath="C:Program FilesPHPphp-cgi.exe" />
</fastCgi>
Any help is very appreciated.
2
Answers
The following code is definitely not a smart and good solution, but maybe you can use it as a workaround until someone here shows us the smart solution, which I’m also very interested in.
I’ve done some tests. It’s still a workaround, but a bit smarter and I think as long as there’s no better solution, you can live with it.
You just have to add
echo str_repeat(" ", 7500000);
at the very beginning of your code andob_flush()
andflush()
will do what they’re supposed to do (also with the new IIS versions):