简体   繁体   中英

HTTP response, Browsers, PHP, how things work

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.


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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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