[英]Flushing HTML to Browser using PHP
我正在嘗試實施此頁面上列出的技巧http://developer.yahoo.com/performance/rules.html#flush “盡早清除緩沖區”。
每次我嘗試運行此東西時,都不會獲得所需的輸出。
我寫了下面的代碼。
<html>
<head>
<title>This is title</title>
<script type="text/javascript" src="/1.js"></script>
<link rel="stylesheet" type="text/css" href="/1.css">
</head>
<body>
ABC
<?php
flush();
sleep(3);
?>
</body>
</html>
結果
我在Firefox和Chrome上都得到了相同的結果。
我期望CSS和JS文件的下載應立即開始,而不要等待3秒鍾。
根據互聯網上提供的信息,我嘗試了以下操作,但沒有任何幫助。
1. ob_start(); and then ob_flush();
2. Using both ob_flush(); and flush(); ( in both the orders )
3. Adding the thing like this
@apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 0);
@ini_set('implicit_flush', 1);
4. Putting more content in body 4~5 KB of content before flush.
5. And many other things.
我懷疑實現這種目標是否切實可行。
嗯...在yahoo的文檔中, flush()
在</head>
和<body>
之前。
... <!-- css, js -->
</head>
<?php flush(); ?>
<body>
... <!-- content -->
在您的代碼中,它在<body>
內部。 您是否嘗試將php代碼放在前面?
嗨,我遇到過同樣的情況,ob_start和ob_flush本身對我也不起作用。
因此,在編輯代碼后,它可以編輯::
<?php
if (ob_get_level() == 0) ob_start();
for($i = 0 ; $i < 10 ; $i++){
echo $i . '<br>';
sleep(1);
echo str_pad('',4096) ;
ob_flush();
flush();
}
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.