PHP100 2019-03-27
<span style="COLOR: #000000"><br> <span style="COLOR: #0000bb"><?php <br>ob_start</span><span style="COLOR: #007700">(); </span><span style="COLOR: #ff8000">//打开缓冲区 <br></span><span style="COLOR: #007700">echo </span><span style="COLOR: #dd0000">"Hellon\"; //输出 <br>header("</span><span style="COLOR: #0000bb">location</span><span style="COLOR: #007700">:</span><span style="COLOR: #0000bb">index</span><span style="COLOR: #007700">.</span><span style="COLOR: #0000bb">php</span><span style="COLOR: #dd0000">"); //把浏览器重定向到index.php <br>ob_end_flush();//输出全部内容到浏览器 <br>?> <br> </span> </span>
<span style="COLOR: #000000"><br><span style="COLOR: #0000bb"><?php <br></span><span style="COLOR: #007700">for(</span><span style="COLOR: #0000bb">$i </span><span style="COLOR: #007700">= </span><span style="COLOR: #0000bb">1</span><span style="COLOR: #007700">; </span><span style="COLOR: #0000bb">$i </span><span style="COLOR: #007700"><= </span><span style="COLOR: #0000bb">300</span><span style="COLOR: #007700">; </span><span style="COLOR: #0000bb">$i</span><span style="COLOR: #007700">++ ) print(</span><span style="COLOR: #dd0000">" "</span><span style="COLOR: #007700">); <br></span><span style="COLOR: #ff8000">// 这一句话非常关键,cache的结构使得它的内容只有达到一定的大小才能从浏览器里输出 <br>// 换言之,如果cache的内容不达到一定的大小,它是不会在程序执行完毕前输出的。经 <br>// 过测试,我发现这个大小的底限是256个字符长。这意味着cache以后接收的内容都会 <br>// 源源不断的被发送出去。 <br></span><span style="COLOR: #007700">For(</span><span style="COLOR: #0000bb">$j </span><span style="COLOR: #007700">= </span><span style="COLOR: #0000bb">1</span><span style="COLOR: #007700">; </span><span style="COLOR: #0000bb">$j </span><span style="COLOR: #007700"><= </span><span style="COLOR: #0000bb">20</span><span style="COLOR: #007700">; </span><span style="COLOR: #0000bb">$j</span><span style="COLOR: #007700">++) { <br>echo </span><span style="COLOR: #0000bb">$j</span><span style="COLOR: #007700">.</span><span style="COLOR: #dd0000">" <br>"</span><span style="COLOR: #007700">; <br></span><span style="COLOR: #0000bb">flush</span><span style="COLOR: #007700">(); </span><span style="COLOR: #ff8000">//这一部会使cache新增的内容被挤出去,显示到浏览器上 <br></span><span style="COLOR: #0000bb">sleep</span><span style="COLOR: #007700">(</span><span style="COLOR: #0000bb">1</span><span style="COLOR: #007700">); </span><span style="COLOR: #ff8000">//让程序"睡"一秒钟,会让你把效果看得更清楚 <br></span><span style="COLOR: #007700">} <br></span><span style="COLOR: #0000bb">?></span> <br></span>
<span style="COLOR: #000000"><br><span style="COLOR: #0000bb"><?php <br>ob_start</span><span style="COLOR: #007700">(); </span><span style="COLOR: #ff8000">//打开缓冲区 <br></span><span style="COLOR: #0000bb">phpinfo</span><span style="COLOR: #007700">(); </span><span style="COLOR: #ff8000">//使用phpinfo函数 <br></span><span style="COLOR: #0000bb">$info</span><span style="COLOR: #007700">=</span><span style="COLOR: #0000bb">ob_get_contents</span><span style="COLOR: #007700">(); </span><span style="COLOR: #ff8000">//得到缓冲区的内容并且赋值给$info <br></span><span style="COLOR: #0000bb">$file</span><span style="COLOR: #007700">=</span><span style="COLOR: #0000bb">fopen</span><span style="COLOR: #007700">('</span><span style="COLOR: #0000bb">info.txt</span><span style="COLOR: #007700">\'</span><span style="COLOR: #0000bb">,</span><span style="COLOR: #007700">\'</span><span style="COLOR: #0000bb">w</span><span style="COLOR: #007700">\'</span><span style="COLOR: #0000bb">); //打开文件info.txt <br>fwrite($file,$info); //写入信息到info.txt <br>fclose($file); //关闭文件info.txt <br>?> <br></span></span>
<span style="COLOR: #000000"><br><span style="COLOR: #0000bb"><?php <br>ob_start</span><span style="COLOR: #007700">();</span><span style="COLOR: #ff8000">//打开缓冲区 <br></span><span style="COLOR: #0000bb">?></span> <br>php页面的全部输出 <br><span style="COLOR: #0000bb"><? <br>$content </span><span style="COLOR: #007700">= </span><span style="COLOR: #0000bb">ob_get_contents</span><span style="COLOR: #007700">();</span><span style="COLOR: #ff8000">//取得php页面输出的全部内容 <br></span><span style="COLOR: #0000bb">$fp </span><span style="COLOR: #007700">= </span><span style="COLOR: #0000bb">fopen</span><span style="COLOR: #007700">(</span><span style="COLOR: #dd0000">"output00001.html"</span><span style="COLOR: #007700">, </span><span style="COLOR: #dd0000">"w"</span><span style="COLOR: #007700">); </span><span style="COLOR: #ff8000">//创建一个文件,并打开,准备写入 <br></span><span style="COLOR: #0000bb">fwrite</span><span style="COLOR: #007700">(</span><span style="COLOR: #0000bb">$fp</span><span style="COLOR: #007700">, </span><span style="COLOR: #0000bb">$content</span><span style="COLOR: #007700">); </span><span style="COLOR: #ff8000">//把php页面的内容全部写入output00001.html,然后…… <br></span><span style="COLOR: #0000bb">fclose</span><span style="COLOR: #007700">(</span><span style="COLOR: #0000bb">$fp</span><span style="COLOR: #007700">); <br></span><span style="COLOR: #0000bb">?></span> <br></span>
<span style="COLOR: #000000"><br><span style="COLOR: #0000bb"><? <br></span><span style="COLOR: #007700">Function </span><span style="COLOR: #0000bb">run_code</span><span style="COLOR: #007700">(</span><span style="COLOR: #0000bb">$code</span><span style="COLOR: #007700">) { <br>If(</span><span style="COLOR: #0000bb">$code</span><span style="COLOR: #007700">) { <br></span><span style="COLOR: #0000bb">ob_start</span><span style="COLOR: #007700">(); <br>eval(</span><span style="COLOR: #0000bb">$code</span><span style="COLOR: #007700">); <br></span><span style="COLOR: #0000bb">$contents </span><span style="COLOR: #007700">= </span><span style="COLOR: #0000bb">ob_get_contents</span><span style="COLOR: #007700">(); <br></span><span style="COLOR: #0000bb">ob_end_clean</span><span style="COLOR: #007700">(); <br>}else { <br>echo </span><span style="COLOR: #dd0000">"错误!没有输出"</span><span style="COLOR: #007700">; <br>exit(); <br>} <br>return </span><span style="COLOR: #0000bb">$contents</span><span style="COLOR: #007700">; <br>} <br></span></span>
<span style="COLOR: #000000"><br><span style="COLOR: #0000bb"><? <br></span><span style="COLOR: #ff8000">/* <br>** Title.........: PHP4 HTTP Compression Speeds up the Web <br>** Version.......: 1.20 <br>** Author........: catoc <[email][email protected][/email]> <br>** Filename......: gzdoc.php <br>** Last changed..: 18/10/2000 <br>** Requirments...: PHP4 >= 4.0.1 <br>** PHP was configured with --with-zlib[=DIR] <br>** Notes.........: Dynamic Content Acceleration compresses <br>** the data transmission data on the fly <br>** code by sun jin hu (catoc) <[email][email protected][/email]> <br>** Most newer browsers since 1998/1999 have <br>** been equipped to support the HTTP 1.1 <br>** standard known as \"content-encoding.\" <br>** Essentially the browser indicates to the <br>** server that it can accept \"content encoding\" <br>** and if the server is capable it will then <br>** compress the data and transmit it. The <br>** browser decompresses it and then renders <br>** the page. <br>** <br>** Modified by John Lim ([email][email protected][/email]) <br>** based on ideas by Sandy McArthur, Jr <br>** Usage........: <br>** No space before the beginning of the first \'<?\' tag. <br>** ------------Start of file---------- <br>** |<? <br>** | include(\'gzdoc.php\'); <br>** |? > <br>** |<HTML> <br>** |... the page ... <br>** |</HTML> <br>** |<? <br>** | gzdocout(); <br>** |? > <br>** -------------End of file----------- <br>*/ <br></span><span style="COLOR: #0000bb">ob_start</span><span style="COLOR: #007700">(); <br></span><span style="COLOR: #0000bb">ob_implicit_flush</span><span style="COLOR: #007700">(</span><span style="COLOR: #0000bb">0</span><span style="COLOR: #007700">); <br>function </span><span style="COLOR: #0000bb">CheckCanGzip</span><span style="COLOR: #007700">(){ <br>global </span><span style="COLOR: #0000bb">$HTTP_ACCEPT_ENCODING</span><span style="COLOR: #007700">; <br>if (</span><span style="COLOR: #0000bb">headers_sent</span><span style="COLOR: #007700">() || </span><span style="COLOR: #0000bb">connection_timeout</span><span style="COLOR: #007700">() || </span><span style="COLOR: #0000bb">connection_aborted</span><span style="COLOR: #007700">()){ <br>return </span><span style="COLOR: #0000bb">0</span><span style="COLOR: #007700">; <br>} <br>if (</span><span style="COLOR: #0000bb">strpos</span><span style="COLOR: #007700">(</span><span style="COLOR: #0000bb">$HTTP_ACCEPT_ENCODING</span><span style="COLOR: #007700">, '</span><span style="COLOR: #0000bb">x-gzip</span><span style="COLOR: #007700">\'</span><span style="COLOR: #0000bb">) !== false) return \"x-gzip\"; <br>if (strpos($HTTP_ACCEPT_ENCODING,</span><span style="COLOR: #007700">\'</span><span style="COLOR: #0000bb">gzip</span><span style="COLOR: #007700">\'</span><span style="COLOR: #0000bb">) !== false) return \"gzip\"; <br>return 0; <br>} <br>/* $level = compression level 0-9, 0=none, 9=max */ <br>function GzDocOut($level=1,$debug=0){ <br>$ENCODING = CheckCanGzip(); <br>if ($ENCODING){ <br>print \"n<!-- Use compress $ENCODING -->n\"; <br>$Contents = ob_get_contents(); <br>ob_end_clean(); <br>if ($debug){ <br>$s = \"<p>Not compress length: \".strlen($Contents); <br>$s .= \" <br>Compressed length: \".strlen(gzcompress($Contents,$level)); <br>$Contents .= $s; <br>} <br>header(\"Content-Encoding: $ENCODING\"); <br>print \"x1fx8bx08x00x00x00x00x00\"; <br>$Size = strlen($Contents); <br>$Crc = crc32($Contents); <br>$Contents = gzcompress($Contents,$level); <br>$Contents = substr($Contents, 0, strlen($Contents) - 4); <br>print $Contents; <br>print pack(</span><span style="COLOR: #007700">\'</span><span style="COLOR: #0000bb">V</span><span style="COLOR: #007700">\'</span><span style="COLOR: #0000bb">,$Crc); <br>print pack(</span><span style="COLOR: #007700">\'</span><span style="COLOR: #0000bb">V</span><span style="COLOR: #007700">\'</span><span style="COLOR: #0000bb">,$Size); <br>exit; <br>}else{ <br>ob_end_flush(); <br>exit; <br>} <br>} <br>?> <br></span></span>