I have a index.php file as below:
ob_end_clean();
header("Connection: close");
ignore_user_abort(true); // optional
ob_start();
for($i=1; $i<100; $i++) {
echo $i . "."; echo ('Text the user will see'); echo '<br>';
}
$size = ob_get_length();
header("Content-Length: $size");
ob_end_flush(); // Will not work
flush();
// At this point, the browser has closed connection to the web server
// Do processing here
sleep(20);
file_put_contents ('test.txt', 'test', FILE_APPEND);
If i run on browser localhost/index.php its work, because it can show 'text the user will see' on screen and no need wait 20 seconds. But if i call it with ajax like as below:
$.ajax({
url: "index.php"
});
It cant show 'text the user will see' for me. And it is work after waited 20 seconds. How can i fix them. Thank you