久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

為什么 readfile() 會(huì)耗盡 PHP 內(nèi)存?

Why does readfile() exhaust PHP memory?(為什么 readfile() 會(huì)耗盡 PHP 內(nèi)存?)
本文介紹了為什么 readfile() 會(huì)耗盡 PHP 內(nèi)存?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

關(guān)于如何有效地使用 PHP 下載文件而不是允許直接 HTTP 請(qǐng)求(以確保文件安全、跟蹤下載等),我看到了許多問(wèn)題.

I've seen many questions about how to efficiently use PHP to download files rather than allowing direct HTTP requests (to keep files secure, to track downloads, etc.).

答案幾乎總是PHP readfile().

  • 在 PHP 中可靠地下載大文件
  • 如何強(qiáng)制下載大文件又不占用太多內(nèi)存?
  • 透明記錄下載的最佳方式?

但是,雖然它在測(cè)試大文件時(shí)效果很好,但當(dāng)它在有數(shù)百個(gè)用戶的實(shí)時(shí)站點(diǎn)上時(shí),下載開(kāi)始掛起并且 PHP 內(nèi)存限制用盡.

BUT, although it works great during testing with huge files, when it's on a live site with hundreds of users, downloads start to hang and PHP memory limits are exhausted.

那么 readfile() 的工作原理是什么導(dǎo)致內(nèi)存在流量高時(shí)爆炸如此嚴(yán)重?我認(rèn)為它應(yīng)該通過(guò)直接寫(xiě)入輸出緩沖區(qū)來(lái)繞過(guò)大量使用 PHP 內(nèi)存?

So what is it about how readfile() works that causes memory to blow up so bad when traffic is high? I thought it's supposed to bypass heavy use of PHP memory by writing directly to the output buffer?

(為了澄清,我正在尋找為什么",而不是我能做什么".我認(rèn)為 Apache 的 mod_xsendfile 是最好的規(guī)避方法)

(To clarify, I'm looking for a "why", not "what can I do". I think that Apache's mod_xsendfile is the best way to circumvent)

推薦答案

Description
int readfile ( string $filename [, bool $use_include_path = false [, resource $context ]] )
Reads a file and writes it to the output buffer*.

PHP 必須讀取文件并將其寫(xiě)入輸出緩沖區(qū).因此,對(duì)于 300Mb 的文件,無(wú)論您編寫(xiě)什么實(shí)現(xiàn)(通過(guò)許多小段或 1 個(gè)大塊),PHP 最終都必須讀取 300Mb 的文件.

PHP has to read the file and it writes to the output buffer. So, for 300Mb file, no matter what the implementation you wrote (by many small segments, or by 1 big chunk) PHP has to read through 300Mb of file eventually.

如果需要多個(gè)用戶下載文件,就會(huì)出現(xiàn)問(wèn)題.(在一臺(tái)服務(wù)器中,托管服務(wù)提供商會(huì)限制分配給每個(gè)托管用戶的內(nèi)存.由于內(nèi)存如此有限,使用緩沖區(qū)不是一個(gè)好主意.)

If multiple user has to download the file, there will be a problem. (In one server, hosting providers will limit memory given to each hosting user. With such limited memory, using buffer is not going to be a good idea. )

我認(rèn)為使用直接鏈接下載文件對(duì)于大文件來(lái)說(shuō)是一種更好的方法.

I think using the direct link to download a file is a much better approach for big files.

這篇關(guān)于為什么 readfile() 會(huì)耗盡 PHP 內(nèi)存?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個(gè)表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設(shè)置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數(shù)組自動(dòng)填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產(chǎn)生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱(chēng) ASC)
主站蜘蛛池模板: 欧美a在线看 | 国产网站在线播放 | 日韩视频一区二区 | 亚洲国产精品久久久久婷婷老年 | 欧美国产日韩精品 | 高清成人av | 精品亚洲一区二区三区 | 欧美日韩国产精品一区 | 国产精品色婷婷久久58 | 妹子干综合 | 国产日韩欧美一区 | 一级a性色生活片久久毛片 午夜精品在线观看 | 性视频一区 | 国产亚洲成av人在线观看导航 | 亚洲视频在线一区 | 激情国产在线 | 久久成人精品一区二区三区 | 一区二区三区中文 | 欧美一级二级视频 | 欧美精品日韩 | 久久看精品 | 免费在线观看黄色av | 国产精品毛片一区二区在线看 | 中文字幕精品一区久久久久 | 欧美在线国产精品 | 欧美韩一区二区三区 | 国产在线永久免费 | 天天弄天天操 | 亚洲播放一区 | 玖玖国产精品视频 | www.黄色片视频 | 嫩草视频在线免费观看 | 日本黄色大片免费看 | 成人av在线播放 | 亚洲欧美日韩中文字幕一区二区三区 | 色天堂影院 | 欧美一级电影免费观看 | 亚洲精品国产综合区久久久久久久 | 欧美aⅴ| 欧美在线一区二区视频 | 最新午夜综合福利视频 |