How about this?
<?php $i = 1; echo str_repeat("\n", 300); // Clears buffer history, only executes once while(1) { echo "test_".$i."\r"; // Now uses carriage return instead of new line sleep(1); $i++; }
the str_repeat() function is executed outside the while , and instead of ending each echo with a new line, it moves the pointer back to the existing line and writes on top of it.
source share