Possible Duplicate:
what is output buffering?
I have some content that takes a while to be generated by PHP. Meanwhile I would like to use this simple JS trick to display a "Loading..." message. The message would disappear as soon as the output is generated.
<p id="loading_msg">Loading...</p>
<h1>Hello</h1>
<?php
sleep(2); // This is the greedy function call
print '<p>This content definitely took a while to be generated !.</p>';
?>
<script type="text/javascript">
var e = document.getElementById("loading_msg");
e.style.display = "none";
</script>
The problem is, instead of sending everything up to sleep(2);
then blocking, it will wait before all the page is generated, and then, send it all at once. It obviously breaks the purpose of my "Loading..." message, because it doesn't appear before the 2 seconds have elapsed. Any ideas of why, and how I could work around this ?