Re: [請益] readfile 效率問題
※ 引述《KoShiyen (http://0rz.net/e70jv)》之銘言:
: 我寫了一個程式過濾下載的使用者
: 通過的才會用 readfile 放檔案給他, 否則會改放拒絕的圖檔
: 可是本來直接下載時很快很容易下載的檔
: 透過 readfile 就變成慢得不得了
: 開一個檔常常要等好幾分鐘才開始下載
: 用不同的 webhost 也是得到同樣的結果
: 請問這是設定的問題還是程式的問題?
: 用 readfile 釋出檔案前需要什麼特別的處理嗎?
: 謝謝.
這是我在別的地方看到的 我也有這個困擾 XD
http://theserverpages.com/php/manual/en/function.readfile.php
regarding php5:
i found out that there is already a disscussion @php-dev about readfile()
and fpassthru() where only exactly 2 MB will be delivered.
so you may use this on php5 to get lager files
<?php
function readfile_chunked($filename,$retbytes=true) {
$chunksize = 1*(1024*1024); // how many bytes per chunk
$buffer = '';
$cnt =0;
// $handle = fopen($filename, 'rb');
$handle = fopen($filename, 'rb');
if ($handle === false) {
return false;
}
while (!feof($handle)) {
$buffer = fread($handle, $chunksize);
echo $buffer;
if ($retbytes) {
$cnt += strlen($buffer);
}
}
$status = fclose($handle);
if ($retbytes && $status) {
return $cnt; // return num. bytes delivered like readfile() does.
}
return $status;
}
?>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.140.55.7
※ 編輯: previa 來自: 220.140.55.7 (07/17 05:14)
※ 編輯: previa 來自: 220.140.55.7 (07/17 05:16)
推
07/17 11:48, , 1F
07/17 11:48, 1F
→
07/17 11:49, , 2F
07/17 11:49, 2F
推
07/17 16:59, , 3F
07/17 16:59, 3F
→
07/17 17:00, , 4F
07/17 17:00, 4F
→
07/17 17:00, , 5F
07/17 17:00, 5F
討論串 (同標題文章)
PHP 近期熱門文章
PTT數位生活區 即時熱門文章