Echoing content sometimes takes a very long time

前端 未结 8 1999
眼角桃花
眼角桃花 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:37

    I had the same problem in the past very similar to yours. I found that this problem can be caused by slow clients. If client fetched half of the page and then hangs, php will wait until client is ready and then sends rest of the content. So it could be not problem on your side.

    Update:

    You can try following scripts on your server to check this. This script put on your server and call it echo.php:

    Then fetch it with this script (change example.com to your domain):

    \n";
    } else {
        $out = "GET /echo.php HTTP/1.1\r\n";
        $out .= "Host: example.com\r\n";
        $out .= "Connection: Close\r\n\r\n";
        fwrite($fp, $out);
        while (!feof($fp)) {
            echo fgets($fp, 5000);
            sleep(1);
        }
        fclose($fp);
    }
    

    I've got echo.php running 27 seconds. When I remove line sleep(1), echo.php takes only 2 seconds to run.

提交回复
热议问题