如何限制來自php腳本的傳出響應速度?所以我有一個腳本生成保持連接的數據。它只是打開文件並讀取它。如何限制傳出速度如何限制從php腳本傳出響應的速度?
(到現在我有這樣的代碼)
if(isset($_GET[FILE]))
{
$fileName = $_GET[FILE];
$file = $fileName;
if (!file_exists($file))
{
print('<b>ERROR:</b> php could not find (' . $fileName . ') please check your settings.');
exit();
}
if(file_exists($file))
{
# stay clean
@ob_end_clean();
@set_time_limit(0);
# keep binary data safe
set_magic_quotes_runtime(0);
$fh = fopen($file, 'rb') or die ('<b>ERROR:</b> php could not open (' . $fileName . ')');
# content headers
header("Content-Type: video/x-flv");
# output file
while(!feof($fh))
{
# output file without bandwidth limiting
print(fread($fh, filesize($file)));
}
}
}
所以,我應該怎麼辦,以限制響應(上限爲例如50 KB /秒)的速度
'flush'ing後的緩衝打印將確保每秒都有穩定的寫入流,儘管並非嚴格必要。 – Chadwick 2010-06-24 14:25:13
請添加正確的評論和沖洗,所以認爲這個答案完全正確。 – Rella 2010-06-25 09:12:00