comet - 请问如何清除php的缓存区
phpcn_u1582
phpcn_u1582 2017-05-16 13:10:26
0
1
415

代码如下

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(); //不太懂ob_clean的作用 mysql_data_seek($getitem,0); sleep(1); }

php缓存区通过ob_flush和flush可以把缓存区的内容输出给浏览器,而ob_clean的作用是清空缓存区,所以预想的结果是每次只输出最后一条数据。但是实际上之前的输出并没有清空,请问怎么实现我的需求呢?

phpcn_u1582
phpcn_u1582

reply all (1)
洪涛

Usage of the following three functions

ob_get_contents() - 返回输出缓冲区的内容 ob_flush() - 冲刷出(送出)输出缓冲区中的内容 ob_clean() - 清空(擦掉)输出缓冲区 ob_end_flush() - 冲刷出(送出)输出缓冲区内容并关闭缓冲 ob_end_clean() - 清空(擦除)缓冲区并关闭输出缓冲 flush() - 刷新输出缓冲     通常是ob_flush();flush()同时一起使用 使用ob_start()把输出那同输出到缓冲区,而不是到浏览器。 然后用ob_get_contents得到缓冲区的数据。

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().

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!