The code is as follows
while(true){
$getitem = mysql_query("select * from bulletin order by id desc limit 1");
$item = mysql_fetch_array($getitem);
echo json_encode($item,JSON_UNESCAPED_UNICODE);
ob_flush();
flush();
ob_clean(); //Don’t quite understand the function of ob_clean
mysql_data_seek($getitem,0);
sleep(1);
}
The PHP cache area can output the contents of the cache area to the browser through ob_flush and flush, and the function of ob_clean is to clear the cache area, so the expected result is to output only the last piece of data each time. But in fact, the previous output is not cleared. How can I achieve my needs?
Usage of the following three functions
ob_start() opens a buffer on the server to save all output. So anytime echo is used, the output will be added to the buffer until the program ends or is terminated using ob_flush(). Then the content of the buffer in the server will be sent to the browser, which will be parsed and displayed by the browser.
The function ob_end_clean will clear the contents of the buffer and close the buffer, but will not output the content.
At this time, a function ob_get_contents() must be used in front of ob_end_clean() to obtain the contents of the buffer.
In this case, the content can be saved to a variable before executing ob_end_clean(), and then the variable can be operated after ob_end_clean().