php supports breakpoint resumption, mainly relying on the header HTTP_RANGE in the HTTP protocol.
HTTP breakpoint resume download principle
Http header Range, Content-Range()
Range and Content are generally used in HTTP headers only for breakpoint downloads -Range entity header,
In the Range user request header, specify the position of the first byte and the position of the last byte, such as (Range: 200-300)
Content-Range is used for response headers
Request to download the entire file:
GET /test.rar HTTP/1.1
Connection: close
Host: 116.1.219.219
Range: bytes=0-801 //General requests to download the entire file are bytes =0- or do not use this header
Generally normal response
HTTP/1.1 200 OK
Content-Length: 801
Content-Type: application/octet-stream
Content-Range: bytes 0 -800/801 //801: Total file size
FileDownload.class.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
demo
1 2 3 4 5 6 7 8 9 10 11 |
|
Breakpoint resume test method:
Use the linux wget command to test the download, wget -c -O file http://xxx
1. Turn off breakpoint resumption first
$flag = $obj->download($file, $name);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
2. Enable breakpoint resume transfer
1 2 3 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
This article explains the file download class that supports breakpoint resume transfer in PHP , please pay attention to php Chinese website for more related content.
Related recommendations:
Introduction to php related syntax skills
##How to automatically generate thumbnails based on url through php
Introducing the method of using php output_buffering cache
The above is the detailed content of Relevant explanation of PHP file download class that supports breakpoint resume transfer. For more information, please follow other related articles on the PHP Chinese website!