PHP readfile() and large files

后端 未结 7 849
逝去的感伤
逝去的感伤 2020-12-05 20:12

When using readfile() -- using PHP on Apache -- is the file immediately read into Apache\'s output buffer and the PHP script execution completed, or does the PHP script exec

7条回答
  •  清歌不尽
    2020-12-05 20:41

    You may still have PHP output buffering active while performing the readfile(). Check that with:

    if (ob_get_level()) ob_end_clean();
    

    or

    while (ob_get_level()) ob_end_clean();
    

    This way theonly remaining output Buffer should be apache's Output Buffer, see SendBufferSize for apache tweaks.

    EDIT

    You can also have a look at mod_xsendfile (an SO post on such usage, PHP + apache + x-sendfile), so that you simply tell the web server you have done the security check and that now he can deliver the file.

提交回复
热议问题