How to display HTML to the browser incrementally over a long period of time?

前端 未结 8 758
生来不讨喜
生来不讨喜 2020-12-05 11:58

Do I need to pass back any HTTP headers to tell the browser that my server won\'t be immediately closing the connection and to display as the HTML is received? Is there anyt

8条回答
  •  再見小時候
    2020-12-05 12:21

    I would just echo / print the HTML as I went. There are a few different ways you can have the script pause before sending the next bit. You shouldn't need to do anything with headers or any special code to tell the browser to wait. As long as your script is still running it will render the HTML it receives from the script.

    echo "";
    while (running)
    {
        echo "printing html... 
    "; } echo ""; //all done

提交回复
热议问题