Echoing content sometimes takes a very long time

前端 未结 8 1993
眼角桃花
眼角桃花 2021-02-19 16:20

I have a script that builds my webpage in one string ($content) and then echo it to the user.

My script looks like this:

$time1= microtime(true);
$conten         


        
相关标签:
8条回答
  • 2021-02-19 16:46

    As it is not possible to tell you the reason without knowing the body of your create_content() function I suggest you to add more "time logging" functions directly inside this function. Making the included code fewer and fewer you will finally find the line that is causing the lag. Knowing the specific line will help you to understand the problem (database, machine load, connection problems to external services, ...).

    0 讨论(0)
  • 2021-02-19 16:56

    You may be able to do this better using output buffers. On a basic level, you use ob_start() to begin writing to an output buffer, and then ob_end_flush() to push it to the client. Here is what php.net has to say about ob_start():

    This function will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer. The contents of this internal buffer may be copied into a string variable using ob_get_contents(). To output what is stored in the internal buffer, use ob_end_flush().

    0 讨论(0)
提交回复
热议问题