Complete X-Accel-Redirect Speed Limit Download Large File Solution

foreword

Internet searches for X-Accel-Redirect speed limit downloads are all the same tutorials. If you develop according to the online tutorials, when downloading large files, the test will fail if you download half of them.

My webmaster site has been researching for a long time, and found that the shared code on the Internet lacks many parameters, so I organize and share a complete X-Accel-Redirect large file download solution.

Preparation

Before writing code, you need to modify the environment configuration , otherwise the download of large files + half of downloads from low-configuration servers will fail.

1. Modify the php upload limit, for example: pagoda->software store->installed~>PHP->.upload limit->change to 10240->save

2. Modify the PHP timeout limit, for example: pagoda->software store->installed->PHP->timeout limit->change to 3600->save

3. Modify nginx upload limit, for example: pagoda->software store->installed~>Nginx->performance adjustment->change connection timeout to 3600-->save

4. Modify the Nginx timeout limit, for example: pagoda->software store->installed~>Nginx->performance adjustment->modify the maximum uploaded file to 10240->save

5. Finally, restart PHP and restart Nginx. It is best to restart the server to be safest.

X-Accel-Redirect example

Then there is a complete X-Accel-Redirect download code example, which has been tested and is perfect without errors. The 1G1H server can download at low speed without failure.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

//限速

$download_rate=202400;

//防止GZIP压缩

header('Cache-Control: no-transform');

//请求类型

header('Content-Type:application/octet-stream');

//下载文件名称

header('Content-Disposition: attachment; filename="'.$filename.'";filename*=utf-8'."''".$filename.".".$ext);

//开始下载

header('X-Accel-Redirect: '.$downurl);

header('X-Sendfile: '.$downurl);

header("X-Accel-Buffering: yes");

header('X-Accel-Limit-Rate: '.$download_rate);

header("Accept-Ranges: none");

$filename is the file name

$ext is the file suffix, you can also not

$downurl is the download file URL

$download_rate is the speed limit in B

The above variables can read their own data by themselves.

Guess you like

Origin blog.csdn.net/winkexin/article/details/131017216