Re: [請益] readfile 效率問題
※ 引述《previa (Southern Cross)》之銘言:
: ※ 引述《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;
: }
: ?>
我試了這個方法發現會有問題,
檔案超過2G變成只下載1k就結束了,
原因是failed to open stream: File too large,
google一下有看到一篇說是因為32bit integer的關係,
可是http://gaaan.com/cafetw?p=97673 這篇又說可以,
最後遇到的問題跟readfile()一樣。
該怎麼解決這問題啊?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 60.244.250.159
※ 編輯: wnick 來自: 60.244.250.159 (12/04 21:27)
→
12/04 22:26, , 1F
12/04 22:26, 1F
→
12/04 22:28, , 2F
12/04 22:28, 2F
→
12/05 11:39, , 3F
12/05 11:39, 3F
→
12/05 11:42, , 4F
12/05 11:42, 4F
→
12/05 11:43, , 5F
12/05 11:43, 5F
→
12/05 11:43, , 6F
12/05 11:43, 6F
→
12/05 12:05, , 7F
12/05 12:05, 7F
→
12/05 12:07, , 8F
12/05 12:07, 8F
→
12/06 19:33, , 9F
12/06 19:33, 9F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 4 之 4 篇):
PHP 近期熱門文章
PTT數位生活區 即時熱門文章