Serving large files with PHP

前端 未结 9 972
北海茫月
北海茫月 2020-12-13 07:51

So I am trying to serve large files via a PHP script, they are not in a web accessible directory, so this is the best way I can figure to provide access to them.

The

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-13 08:15

    One of benefits of fpassthru() is that this function can work not only with files but any valid handle. Socket for example.

    And readfile() must be a little faster, cause of using OS caching mechanism, if possible (as like as file_get_contents()).

    One more tip. fpassthru() hold handle open, until client gets content (which may require quite a long time on slow connect), and so you must use some locking mechanism if parallel writes to this file possible.

提交回复
热议问题