HTTP 响应、浏览器、PHP、工作原理
http://dev-tips.com/featured /web-developers-a-beginners-guide 的输出缓冲
如果没有输出缓冲(默认设置),当 PHP 通过脚本进行处理时,您的 HTML 会被分段发送到浏览器。通过输出缓冲,您的 HTML 存储在一个变量中,并作为脚本末尾的一个片段发送到浏览器。您是否已经开始看到性能优势和后处理机会?
我读了那篇文章并开始想知道这个过程到底是如何运作的。如果有人能给我一个链接或一个书名,让我可以研究这个问题,那就太好了。当然你可以在这里解释一下。
我认为这个过程是这样的。浏览器将请求发送到服务器,脚本运行,准备就绪后,它会创建响应并将其发送到浏览器。
但看起来它实际上以碎片或其他形式发送响应中的身体部分。我的意思是,即使脚本仍在运行,它也可以先发送标头。对于浏览器来说,即使脚本尚未准备好,它也可以开始渲染页面。
我做了这个愚蠢的测试用例。 :D 嗯,我从浏览器和终端尝试过,我实际上可以看到脚本是如何运行的。区别在于浏览器不会显示第一个回显,然后 10 秒后显示另一个回显。
echo "Yo";
sleep(10);
echo "Yo yo";
很高兴知道整个过程实际上是如何进行的。
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. With output buffering, your HTML is stored in a variable and sent to the browser as one piece at the end of your script. 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. What is the difference is that browser wont show the first echo and then after 10 seconds the other echo.
echo "Yo";
sleep(10);
echo "Yo yo";
It would be nice to know how actually the whole process goes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你读过 ob_start() 和其他函数,如
Ob_get_contents< /代码>,
Ob_end_clean
,Ob_end_flush
,php 网站上的
Ob_get_clean
。
请阅读此处并阅读下面所有这些函数给出的示例,您一定会获得最好的知识。
很高兴能帮助你 :)
did u read ob_start() and other functions like
Ob_get_contents
,Ob_end_clean
,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.
Happy to Help :)