简体   繁体   English

HTTP响应,浏览器,PHP,工作方式

[英]HTTP response, Browsers, PHP, how things work

http://dev-tips.com/featured/output-buffering-for-web-developers-a-beginners-guide http://dev-tips.com/featured/output-buffering-for-web-developers-a-beginners-guide

Without output buffering (the default), your HTML is sent to the browser in pieces as PHP processes through your script. 如果没有输出缓冲(默认值),作为PHP处理通过脚本的HTML被发送到片浏览器。 With output buffering, your HTML is stored in a variable and sent to the browser as one piece at the end of your script. 与输出缓冲,你的HTML被存储在一个变量,在脚本的末尾发送到浏览器为一体。 Can you already begin to see the performance advantages and post processing opportunities? 你已经可以开始看到性能优势和后处理的机会?

I read that article and started to wonder how exactly the process works. 我读了那篇文章,开始怀疑该过程是如何工作的。 It would be nice if somebody could give me a link or a book title where I could study this out. 这将是很好,如果有人可以给我一个链接或书名,我可以学习这一点。 And of course you can explain it here. 当然,您可以在这里进行解释。

I`ve thought that process goes something like this. 我认为该过程类似这样。 Browser send the request to server and the script runs and when it is ready then it creates the response and sends it out to the browser. 浏览器将请求发送到服务器,脚本运行,准备就绪后,它将创建响应并将其发送到浏览器。

But looks like it actually sends the body part in the response in pieces or something. 但是看起来它实际上以碎片之类的形式发送了响应中的身体部位。 I mean it can send out the headers first even if the script is still running. 我的意思是,即使脚本仍在运行,它也可以首先发送标头。 And what goes to the browser is that it waits and waits and can start to render the page even if the script is not ready yet. 而且浏览器需要等待的是,即使脚本尚未准备好,它也可以开始渲染页面。

I made this silly testcase. 我做了这个愚蠢的测试用例。 :D Well I tried it from the browser and from the terminal and I could actually see how the script runs. :D嗯,我试了一下,从浏览器,从终端,我其实可以看到如何运行该脚本。 What is the difference is that browser wont show the first echo and then after 10 seconds the other echo. 有什么区别的是,浏览器不会显示第一回波,然后10秒后对方回音。

echo "Yo";
sleep(10);
echo "Yo yo";

It would be nice to know how actually the whole process goes. 知道整个过程是如何进行的,这真是太好了。


did u read ob_start( ) and other functions like 您是否阅读过ob_start( )和其他功能,例如

Ob_get_contents , Ob_get_contents
Ob_end_clean , Ob_end_clean
Ob_end_flush , Ob_end_flush
Ob_get_clean

on php website.. please read there and also read the given example below all these functions and you will definitely get the best knowledge. php网站上..请阅读这里,并在所有这些功能下面阅读给定的示例,您一定会获得最好的知识。

Happy to Help :) 乐意效劳 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM