Difference between flush, ob_flush and ob_end_flush

Functions ob_flush and ob_end_flush, both are for pushing content sending to browser. But what is the difference?


1, ob_flush: this function will only get content from buffer(memory) and send it to browser, do not distory the buffer space(memory), php script can continue to output content into this memory.


Example: when you want to echo a big page with much content, firstly you only want to output the header info and the sidebar, then you can use ob_flush to do it. After you sent those content, you can continue to put other part of content into this buffer(memory).


2, ob_end_flush: this function will get all contents from buffer(memory) and send to browser, then the engin will destory the buffer place(memory). No content can be saved in this buffer.

Example: take above one, after sending the header info and part of page content, you can call ob_end_flush to send all buffer content to browser and destory the buffer storage.


3, ob_flush and ob_end_flush is sending the buffer content which start the place you calling function "ob_start".


4, "flush" will send output of php itself and its caller.


When PHP running as module of Apache, the "flush" and "ob_flush" will not work immediately due to some reasons:

1, flush may not overide the buffering scheme of your web server.

2, modules like mod_gzip will do buffering of their own that will cause flush not result in daba being sent immediately to browser.

3,Some version of browser will not immdiately display the content from server after recceived it. For example: no line of end, tag of end will make the content not to display in browser.



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章