ag.php
<?php
ignore_user_abort(true);
set_time_limit(0);
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
$i=0;
while(1){
echo $i;
$i++;
ob_flush();
flush();
if (connection_aborted()){
break;
}
usleep(1000000);
}
ajax:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
console.log(xhttp.readyState+" "+xhttp.status);
if (xhttp.readyState === 3 && xhttp.status ===200) {
console.log(xhttp.responseText+"\n");
}
};
xhttp.open("GET", "ag.php", true);
xhttp.send();
hi, at above code, i want to make a persistent connection with php and echo data in while block in 1 second interval and data comes browser like this;
0
01
012
0123
...
but i want echo data to browser like;
0
1
2
3
...
but couldn't achive it so i found this [How to clear previously echoed items in PHP
about my question but not exactly what i want i think.
anybody know is there any way to empty/remove previous echoed data? is it possible? help please.