how to make echo print out right away in PHP?

…衆ロ難τιáo~ 提交于 2019-12-01 05:47:27

If output buffering is on, then flushing it is the only way to output anything to the browser. If you want to output right away then turn of output buffering. If that is not in your control you can just call ob_end_flush() at the srart of your script which will turn the output buffering off. There is no way however to let some messages pass, and some not (without writing custom echo/print functions)

calling ob_end_flush() will flush and turn off the top most output buffer. To make sure all output buffers are turned off and flushes you can easily do this:

while (@ob_end_flush());

It will depend on your webserver. Calling flush will flush the output of whatever current buffer is open, however, as it says on the linked page:

flush() has no effect on the buffering scheme of your web server or the browser on the client side. Thus you need to call both ob_flush() and flush() to flush the output buffers.

Several servers, especially on Win32, will still buffer the output from your script until it terminates before transmitting the results to the browser.

Server modules for Apache like mod_gzip may do buffering of their own that will cause flush() to not result in data being sent immediately to the client.

You could turn off output-buffering on your development/test-server. Change the output_buffering variable in your php.ini configuration file.

ob_end_flush() will throw a notice if it is used at the top of the script when there is no buffer to flush. This may be an issue if you are planning to set cookies or headers. I found it did not affect the buffering on my shared server (Rackspace Reseller).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!