When i build a set of elements (say 100) with php (in a loop) Is the page send to the client only when the loop is completed or is the page on client side already showing on the client before the loop is completed? Thanks
You can control output to client browser anytime in your PHP code
Example Send to Client Instantly
for($i = 0; $i < 100; $i ++) {
echo $i, " - sent ";
sleep(1);
flush(); // Send to client Instantly
}
Example Send after Loop
ob_start();
for($i = 0; $i < 100; $i ++) {
echo $i, " - sent ";
sleep(1);
}
ob_end_flush() // Send after loop
Example 3 ( This would just use your default output buffer configuration )
for($i = 0; $i < 100; $i ++) {
echo $i, " - sent ";
sleep(1);
}
Finally (Credit : Ninsuo)
Some browsers does not display anything until the page is fully loaded so we don't always control flushing
it depends how your output buffering is configured.
You can see the different options here.
I would say that you can't rely on anything being shown to the user until the script ends. While you may be able to set PHP's buffering settings, this then will go through Apache which may or may not buffer, and then to the browser, which also may or may not buffer.
The safest way to show the user bits of data when they are available is through AJAX calls from the client browser after the page has loaded.