{"id":1269,"date":"2018-08-29T17:26:52","date_gmt":"2018-08-29T09:26:52","guid":{"rendered":"http:\/\/www.iooe.cn\/?p=1269"},"modified":"2018-08-29T17:26:52","modified_gmt":"2018-08-29T09:26:52","slug":"%e5%85%b3-php-ob_flush%e5%87%bd%e6%95%b0%e7%94%a8%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"http:\/\/www.iooe.cn\/index.php\/2018\/08\/29\/%e5%85%b3-php-ob_flush%e5%87%bd%e6%95%b0%e7%94%a8%e6%96%b9%e6%b3%95\/","title":{"rendered":"\u5173 php  ob_flush()\u51fd\u6570\u7528\u65b9\u6cd5"},"content":{"rendered":"<p>\n\t1. \u670d\u52a1\u5668\u53cc\u52a8\u529b\u7684\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nginx\/conf&nbsp; &nbsp; \u4e0b\u7684nginx.conf&nbsp;&nbsp;\u91cc\u9762<\/p>\n<p>\t&nbsp; &nbsp; &nbsp; &nbsp; \u5173\u6389&nbsp;&nbsp;<br \/>\n\tgzip&nbsp;&nbsp;off;<br \/>\n\tfastcgi_keep_conn on;<br \/>\n\t\u52a0\u5165\u4e0a\u9762\u4e24\u53e5\u3002<\/p>\n<p>\t\u5728\/www\/wdlinux\/phps\/53\/etc\/php.ini&nbsp;<\/p>\n<p>\t\u5728\u8fd9\u91cc\u9762\u5173\u6389<br \/>\n\toutput_<strong><font color=\"#FF0000\">buffer<\/font><\/strong>ing = off<\/p>\n<p>\t\u4e0a\u9762\u8fd9\u53e5\u3002&nbsp;<br \/>\n\t\u90fd\u91cd\u542f\u670d\u52a1\u8bd5\u4e00\u4e0b\u3002\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t2. \u53ef\u7528\u7684\u4ee3\u7801:\n<\/p>\n<p>\n\t<a href=\"http:\/\/www.iooe.cn\/wp-content\/uploads\/2018\/08\/\u5c4f\u5e55\u5feb\u7167-2018-08-29-\u4e0b\u53485.24.18.png\"><img loading=\"lazy\" alt=\"\" class=\"alignnone size-full wp-image-1270\" height=\"408\" src=\"http:\/\/www.iooe.cn\/wp-content\/uploads\/2018\/08\/\u5c4f\u5e55\u5feb\u7167-2018-08-29-\u4e0b\u53485.24.18.png\" width=\"772\" srcset=\"http:\/\/www.iooe.cn\/wp-content\/uploads\/2018\/08\/\u5c4f\u5e55\u5feb\u7167-2018-08-29-\u4e0b\u53485.24.18.png 772w, http:\/\/www.iooe.cn\/wp-content\/uploads\/2018\/08\/\u5c4f\u5e55\u5feb\u7167-2018-08-29-\u4e0b\u53485.24.18-300x159.png 300w, http:\/\/www.iooe.cn\/wp-content\/uploads\/2018\/08\/\u5c4f\u5e55\u5feb\u7167-2018-08-29-\u4e0b\u53485.24.18-768x406.png 768w\" sizes=\"(max-width: 772px) 100vw, 772px\" \/><\/a>\n<\/p>\n<p>\n\t&lt;?php<br \/>\n\t&nbsp; &nbsp; header(&#39;Content-Type: text\/html; charset=utf-8&#39;);\n<\/p>\n<p>\n\t&nbsp; &nbsp; \/\/ I think maybe you can set output_buffering using ini_set here, but I&#39;m not sure.<br \/>\n\t&nbsp; &nbsp; \/\/ It didn&#39;t work for me the first time at least, but now it does sometimes&#8230;<br \/>\n\t&nbsp; &nbsp; \/\/ So I set output_buffering to Off in my php.ini,<br \/>\n\t&nbsp; &nbsp; \/\/ which normally, on Linux, you can find at the following location: \/etc\/php5\/apache2\/php.ini<br \/>\n\t&nbsp; &nbsp; @ini_set(&#39;output_buffering&#39;,&#39;Off&#39;);<br \/>\n\t&nbsp; &nbsp; @ini_set(&#39;zlib.output_compression&#39;,0);<br \/>\n\t&nbsp; &nbsp; @ini_set(&#39;implicit_flush&#39;,1);<br \/>\n\t&nbsp; &nbsp; @ob_end_clean();<br \/>\n\t&nbsp; &nbsp; set_time_limit(0);<br \/>\n\t&nbsp; &nbsp; ob_start();\n<\/p>\n<p>\n\t&nbsp; &nbsp; echo str_repeat(&#39; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&#39;,1024*8); \/\/&lt;&#8211; For some reason it now even works without this, in Firefox at least or in Safari&nbsp;?<br \/>\n\t&nbsp;&nbsp; &nbsp;\/\/ob_flush();<br \/>\n\t&nbsp;&nbsp; &nbsp;\/\/ob_implicit_flush();<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;\/\/ob_flush();<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;\/\/flush();<br \/>\n\t&nbsp;&nbsp; &nbsp;<br \/>\n\t&nbsp;&nbsp; &nbsp;for($j = 1; $j &lt;= 20; $j++) { &nbsp;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;echo &quot;-&gt;&quot;;<br \/>\n\t&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;ob_flush();<br \/>\n\t&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\/\/flush(); &nbsp;&nbsp;<br \/>\n\t&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;echo $j.&quot; &quot;; &nbsp;<br \/>\n\t&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;sleep(1);<br \/>\n\t&nbsp;&nbsp; &nbsp;<br \/>\n\t&nbsp;&nbsp; &nbsp;}&nbsp;\n<\/p>\n<p>\n\t?&gt;&nbsp;\n<\/p>\n<p>\n\t<strong>&nbsp; &nbsp; echo str_repeat(&#39; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&#39;,1024*8); \/\/&lt;&#8211; For some reason it now even works without this, in Firefox at least or in Safari&nbsp;?<\/strong><br \/>\n\t&nbsp;\n<\/p>\n<p>\n\t\u4e0a\u9762\u8fd9\u4e2a\u662f\u91cd\u70b9\u3002 \u6709\u4e9b\u6d4f\u89c8\u5668\u4e0d\u597d\u4f7f\uff0c \u5c31\u8981\u7528\u8fd9\u4e2a\u3002&nbsp;\n<\/p>\n<p>\n\t\u6211\u7684mac\u4e0a\u5c31\u662f\u4e0d\u884c\u3002 \u540e\u4e3a\u52a0\u4e86\u8fd9\u53e5\u7684\u4ee3\u7801\u5c31\u53ef\u4ee5\u4e86\u3002&nbsp;\n<\/p>\n<p>\n\t\u539f\u521b\uff0c \u8f6c\u53d1\u7559\u5730\u5740\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. \u670d\u52a1\u5668\u53cc\u52a8\u529b\u7684 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nginx\/conf&nbsp; &nbsp; \u4e0b\u7684nginx.con&#8230; <\/p>\n<div class='button-mores'><a href='http:\/\/www.iooe.cn\/index.php\/2018\/08\/29\/%e5%85%b3-php-ob_flush%e5%87%bd%e6%95%b0%e7%94%a8%e6%96%b9%e6%b3%95\/'> \u9605\u8bfb\u66f4\u591a&#8230; <\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[],"_links":{"self":[{"href":"http:\/\/www.iooe.cn\/index.php\/wp-json\/wp\/v2\/posts\/1269"}],"collection":[{"href":"http:\/\/www.iooe.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.iooe.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.iooe.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.iooe.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1269"}],"version-history":[{"count":1,"href":"http:\/\/www.iooe.cn\/index.php\/wp-json\/wp\/v2\/posts\/1269\/revisions"}],"predecessor-version":[{"id":1271,"href":"http:\/\/www.iooe.cn\/index.php\/wp-json\/wp\/v2\/posts\/1269\/revisions\/1271"}],"wp:attachment":[{"href":"http:\/\/www.iooe.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.iooe.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1269"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.iooe.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}