Methods ob_start and ob_flush don't work, why?

前端 未结 7 1102
时光取名叫无心
时光取名叫无心 2020-12-29 11:49

I am using ob_start()/ob_flush() to, hopefully, give me some progress during a long import operation.

Here is a simple outline of what I\'m

7条回答
  •  自闭症患者
    2020-12-29 12:29

    It's possible that your webserver is doing its own buffering. Probably with something like mod_gzip.

    Here is some very simple test code:

    ';
    for($i = 0; $i < 5; $i++) {
      print "$i
    "; flush(); sleep(2); } print 'DONE!
    ';

    If it takes 10 seconds for that page to load, rather than seeing a new line every 2 seconds, then it means that it is being cached by your webserver. For what you are trying to do, there is no need to use ob_start and ob_flush. Just call flush whenever you want to force the content to the browser. However, like I mentioned, if the webserver is waiting for the content to complete before sending, then that won't do anything for you.

    Edit: Another possibility is that you're viewing the page from behind a corporate or ISP proxy/firewall that waits for the whole page before serving it (so that it can scan it to see if it looks like pornography, for example).

提交回复
热议问题